Skip to content

Commit d29a143

Browse files
supervacuusjjbayer
andauthored
fix: use goblin permissive PE parse-mode (#960)
* fix: use goblin permissive PE parse-mode * Update CHANGELOG.md Co-authored-by: Joris Bayer <joris.bayer@sentry.io> * add snapshot test for msys2 PE+DWARF debug file --------- Co-authored-by: Joris Bayer <joris.bayer@sentry.io>
1 parent 5024ae6 commit d29a143

8 files changed

Lines changed: 552 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
**Fixes**
6+
7+
- Use goblin permissive PE parse-mode ([#960](https://github.com/getsentry/symbolic/pull/960))
8+
39
## 12.17.2
410

511
**Fixes**

Cargo.lock

Lines changed: 26 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ gimli = { version = "0.32.3", default-features = false, features = [
2828
"std",
2929
"fallible-iterator",
3030
] }
31-
goblin = { version = "0.8.0", default-features = false }
31+
goblin = { version = "0.10.5", default-features = false }
3232
indexmap = "2.0.0"
3333
insta = { version = "1.28.0", features = ["yaml"] }
3434
itertools = "0.14.0"
@@ -48,7 +48,7 @@ proptest = "1.6.0"
4848
regex = "1.7.1"
4949
rustc-demangle = "0.1.21"
5050
# keep this in sync with whatever version `goblin` uses
51-
scroll = "0.12.0"
51+
scroll = "0.13.0"
5252
serde = { version = "1.0.171", features = ["derive"] }
5353
serde_json = "1.0.102"
5454
similar-asserts = "1.4.2"

symbolic-debuginfo/src/pe.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ impl<'data> PeObject<'data> {
8383

8484
/// Tries to parse a PE object from the given slice.
8585
pub fn parse(data: &'data [u8]) -> Result<Self, PeError> {
86-
let pe = pe::PE::parse(data).map_err(PeError::new)?;
86+
let opts = pe::options::ParseOptions::default()
87+
.with_parse_mode(goblin::pe::options::ParseMode::Permissive);
88+
let pe = pe::PE::parse_with_opts(data, &opts).map_err(PeError::new)?;
8789
let is_stub = is_pe_stub(&pe);
8890
Ok(PeObject { pe, data, is_stub })
8991
}
@@ -122,7 +124,11 @@ impl<'data> PeObject<'data> {
122124
debug_data
123125
.codeview_pdb70_debug_info
124126
.as_ref()
125-
.map(|cv_record| (debug_data.image_debug_directory, cv_record))
127+
.map(|cv_record| {
128+
let debug_directory =
129+
debug_data.find_type(goblin::pe::debug::IMAGE_DEBUG_TYPE_CODEVIEW);
130+
(debug_directory, cv_record)
131+
})
126132
})
127133
.and_then(|(debug_directory, cv_record)| {
128134
let guid = &cv_record.signature;
@@ -136,8 +142,8 @@ impl<'data> PeObject<'data> {
136142
// > Matching PDB ID is stored in the #Pdb stream of the .pdb file.
137143
//
138144
// See https://github.com/dotnet/runtime/blob/main/docs/design/specs/PE-COFF.md#codeview-debug-directory-entry-type-2
139-
let age = if debug_directory.minor_version == 0x504d {
140-
debug_directory.time_date_stamp
145+
let age = if let Some(d) = debug_directory.filter(|d| d.minor_version == 0x504d) {
146+
d.time_date_stamp
141147
} else {
142148
cv_record.age
143149
};
@@ -191,7 +197,7 @@ impl<'data> PeObject<'data> {
191197
/// load address, so that the caller only has to deal with addresses relative to the actual
192198
/// start of the image.
193199
pub fn load_address(&self) -> u64 {
194-
self.pe.image_base as u64
200+
self.pe.image_base
195201
}
196202

197203
/// Determines whether this object exposes a public symbol table.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
source: symbolic-debuginfo/tests/test_objects.rs
3+
expression: object
4+
---
5+
Pe(
6+
PeObject {
7+
code_id: Some(
8+
CodeId(695cfde9cf000),
9+
),
10+
debug_id: DebugId {
11+
uuid: "fe9537f1-e434-a859-4c4c-44205044422e",
12+
appendix: 1,
13+
},
14+
debug_file_name: Some(
15+
"",
16+
),
17+
arch: Amd64,
18+
kind: Library,
19+
load_address: 0x180000000,
20+
has_symbols: false,
21+
has_debug_info: true,
22+
has_unwind_info: true,
23+
is_malformed: false,
24+
},
25+
)

0 commit comments

Comments
 (0)