Skip to content
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

**Breaking Changes**

- `SourceBundleWriter::finish` now returns the underlying writer. ([#1016](https://github.com/getsentry/symbolic/pull/1016))
- `FormatErrorKind::InvalidBlobFormat` is changed from `u32` to `i32`. ([#1016](https://github.com/getsentry/symbolic/pull/1016))
- `EmbeddedSource::get_contents_bounded` now replaces `EmbeddedSource::get_contents`. ([#1016](https://github.com/getsentry/symbolic/pull/1016))

## 14.0.0-alpha.2

**Fixes**
Expand Down
2 changes: 1 addition & 1 deletion symbolic-debuginfo/src/ppdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<'data> PortablePdbDebugSession<'data> {
match sources.get(path) {
None => Ok(None),
Some(PPDBSource::Embedded(source)) => source
.get_contents_bounded(self.max_decompressed_embedded_source_size)
.get_contents(self.max_decompressed_embedded_source_size)
.map(|bytes| {
Some(SourceFileDescriptor::new_embedded(
from_utf8_cow_lossy(&bytes),
Expand Down
9 changes: 2 additions & 7 deletions symbolic-debuginfo/src/sourcebundle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,18 +1514,13 @@ where
}

let is_empty = self.is_empty();
let writer = self.do_finish()?;
let writer = self.finish()?;

Ok((!is_empty, writer))
}

/// Writes the manifest to the bundle and flushes the underlying file handle.
pub fn finish(self) -> Result<(), SourceBundleError> {
self.do_finish().map(drop)
}

/// Writes the manifest to the bundle and flushes the underlying file handle.
fn do_finish(mut self) -> Result<W, SourceBundleError> {
pub fn finish(mut self) -> Result<W, SourceBundleError> {
self.write_manifest()?;
let writer = self
.writer
Expand Down
24 changes: 6 additions & 18 deletions symbolic-ppdb/src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub enum FormatErrorKind {
InvalidCustomDebugInformationTag(u32),
/// Tried to read contents of a blob in an unknown format.
#[error("invalid blob format {0}")]
InvalidBlobFormat(u32),
InvalidBlobFormat(i32),
/// Failed to parse Source Link JSON
#[error("invalid source link JSON")]
InvalidSourceLinkJson,
Expand Down Expand Up @@ -478,16 +478,11 @@ impl<'data, 'object> EmbeddedSource<'data> {
self.document.name.as_str()
}

/// Reads the source file contents from the Portable PDB.
pub fn get_contents(&self) -> Result<Cow<'data, [u8]>, FormatError> {
self.get_contents_bounded(None)
}

/// Reads the source file contents from the Portable PDB.
///
/// If the contents are compressed, the decompressed size
/// can be bounded with `max_decompressed_size`.
pub fn get_contents_bounded(
pub fn get_contents(
&self,
max_decompressed_size: Option<usize>,
) -> Result<Cow<'data, [u8]>, FormatError> {
Expand All @@ -501,26 +496,19 @@ impl<'data, 'object> EmbeddedSource<'data> {
return Err(FormatErrorKind::InvalidBlobData.into());
}
let (format_blob, data_blob) = self.blob.split_at(4);
let format = u32::from_ne_bytes(format_blob.try_into().unwrap());

// Per the above comment, the format is really an `i32`.
// None-negative values are currently valid, negative ones are reserved.
// We can't trivially change this to an `i32`, though, because of
// `FormatErrorKind::InvalidBlobFormat`, which expects a `u32`.
// Therefore, we manually bound the format here to the largest
// positive `i32`.
const MAX_VALID_FORMAT: u32 = i32::MAX as u32;
let format = i32::from_ne_bytes(format_blob.try_into().unwrap());

match format {
0 => Ok(Cow::Borrowed(data_blob)),
1..=MAX_VALID_FORMAT => {
1.. => {
let size = format as usize;
if max_decompressed_size.is_some_and(|max| size > max) {
return Err(FormatErrorKind::EmbeddedSourceFileSizeExceeded(size).into());
}
self.inflate_contents(size, data_blob)
}
_ => Err(FormatErrorKind::InvalidBlobFormat(format).into()),
// Negative numbers are reserved for future formats.
..0 => Err(FormatErrorKind::InvalidBlobFormat(format).into()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion symbolic-ppdb/tests/test_ppdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn test_embedded_sources() {
}

fn check_contents(item: &EmbeddedSource, length: usize, name: &str) {
let content = item.get_contents().unwrap();
let content = item.get_contents(None).unwrap();
assert_eq!(content.len(), length);

let expected = std::fs::read(format!("tests/fixtures/contents/{name}")).unwrap();
Expand Down
Loading