Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ppdb): Parse streams in the correct order #760

Merged
merged 4 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Fixes**:

- Make sure to parse `PortablePdb` streams in the correct order. ([#760](https://github.com/getsentry/symbolic/pull/760))

## 11.1.0

**Features**:
Expand Down
3 changes: 1 addition & 2 deletions symbolic-debuginfo/tests/test_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,9 @@ fn test_ppdb_has_sources() -> Result<(), Error> {
assert_eq!(object.has_sources(), true);
}
{
// This is a special case with a broken file, see symbolic-ppdb tests.
let view = ByteView::open(fixture("android/Sentry.Samples.Maui.pdb"))?;
let object = Object::parse(&view)?;
assert_eq!(object.has_sources(), false);
assert_eq!(object.has_sources(), true);
}
Ok(())
}
Expand Down
23 changes: 14 additions & 9 deletions symbolic-ppdb/src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ impl<'data> PortablePdb<'data> {
guid_stream: None,
};

let mut metadata_stream = None;
for _ in 0..stream_count {
let (header, after_header_buf) = raw::StreamHeader::ref_from_prefix(streams_buf)
.ok_or(FormatErrorKind::InvalidStreamHeader)?;
Expand Down Expand Up @@ -260,22 +261,26 @@ impl<'data> PortablePdb<'data> {

match name {
"#Pdb" => result.pdb_stream = Some(PdbStream::parse(stream_buf)?),
"#~" => {
result.metadata_stream = Some(MetadataStream::parse(
stream_buf,
result
.pdb_stream
.as_ref()
.map_or([0; 64], |s| s.referenced_table_sizes),
)?)
}
// Save the #~ stream for last; it definitely must be parsed after the #Pdb stream.
"#~" => metadata_stream = Some(stream_buf),
"#Strings" => result.string_stream = Some(StringStream::new(stream_buf)),
"#US" => result.us_stream = Some(UsStream::new(stream_buf)),
"#Blob" => result.blob_stream = Some(BlobStream::new(stream_buf)),
"#GUID" => result.guid_stream = Some(GuidStream::parse(stream_buf)?),
_ => return Err(FormatErrorKind::UnknownStream.into()),
}
}

if let Some(stream_buf) = metadata_stream {
result.metadata_stream = Some(MetadataStream::parse(
stream_buf,
result
.pdb_stream
.as_ref()
.map_or([0; 64], |s| s.referenced_table_sizes),
)?)
}

Ok(result)
}

Expand Down
6 changes: 2 additions & 4 deletions symbolic-ppdb/tests/test_ppdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,14 @@ fn test_embedded_sources_contents() {
);
}

/// This is here to prevent regression. The following test PDB was built in sentry-dotnet MAUI
/// sample for net6.0-android and failed with: `InvalidCustomDebugInformationTag(0)`
#[test]
fn test_embedded_sources_with_metadata_broken() {
fn test_embedded_sources_with_metadata_maui() {
let buf = std::fs::read(fixture("android/Sentry.Samples.Maui.pdb")).unwrap();

let ppdb = PortablePdb::parse(&buf).unwrap();
let iter = ppdb.get_embedded_sources().unwrap();
let items = iter.collect::<Result<Vec<_>, _>>().unwrap();
assert_eq!(items.len(), 0);
assert_eq!(items.len(), 5);
}

#[test]
Expand Down