diff --git a/CHANGELOG.md b/CHANGELOG.md index f60d97ee2..e8a44e44e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +**Fixes** + +- symcache: Fixed an unsound implementation of `Pod` ([#958](https://github.com/getsentry/symbolic/pull/958)) + ## 12.17.1 **Fixes** diff --git a/symbolic-symcache/src/lib.rs b/symbolic-symcache/src/lib.rs index d0d9f7b1d..9eea45866 100644 --- a/symbolic-symcache/src/lib.rs +++ b/symbolic-symcache/src/lib.rs @@ -152,7 +152,7 @@ impl std::fmt::Debug for SymCache<'_> { f.debug_struct("SymCache") .field("version", &self.header.version) .field("debug_id", &self.header.debug_id) - .field("arch", &self.header.arch) + .field("arch", &Arch::from_u32(self.header.arch)) .field("files", &self.header.num_files) .field("functions", &self.header.num_functions) .field("source_locations", &self.header.num_source_locations) @@ -256,7 +256,7 @@ impl<'data> SymCache<'data> { /// The architecture of the symbol file. pub fn arch(&self) -> Arch { - self.header.arch + Arch::from_u32(self.header.arch) } /// The debug identifier of the cache file. diff --git a/symbolic-symcache/src/raw.rs b/symbolic-symcache/src/raw.rs index 1d29cd87c..88764aa1b 100644 --- a/symbolic-symcache/src/raw.rs +++ b/symbolic-symcache/src/raw.rs @@ -3,7 +3,7 @@ use watto::Pod; -use symbolic_common::{Arch, DebugId}; +use symbolic_common::DebugId; /// The magic file preamble as individual bytes. const SYMCACHE_MAGIC_BYTES: [u8; 4] = *b"SYMC"; @@ -37,7 +37,10 @@ pub(crate) struct Header { /// Debug identifier of the object file. pub(crate) debug_id: DebugId, /// CPU architecture of the object file. - pub(crate) arch: Arch, + /// + /// This cannot be [`symbolic_common::Arch`] because + /// not every bit pattern is valid for that type. + pub(crate) arch: u32, /// Number of included [`File`]s. pub(crate) num_files: u32, @@ -142,4 +145,17 @@ mod tests { assert_eq!(mem::size_of::(), 4); assert_eq!(mem::align_of::(), 4); } + + #[test] + fn test_header_arch_from_bytes() { + // Create an array of `u32`s and later transmute it to a slice of `u8`. + // This is to get a `u8` slice which is 4-byte aligned. + let mut nums = [0u32; 20]; + // There are 40B, or 10 `u32`, before `arch` in the header. + nums[10] = 17; + let ptr = &raw const nums as *const u8; + let bytes: &[u8] = unsafe { std::slice::from_raw_parts(ptr, 80) }; + + let _arch = Header::ref_from_bytes(bytes).unwrap().arch; + } } diff --git a/symbolic-symcache/src/writer.rs b/symbolic-symcache/src/writer.rs index 728f95e1e..ed79341fd 100644 --- a/symbolic-symcache/src/writer.rs +++ b/symbolic-symcache/src/writer.rs @@ -489,7 +489,7 @@ impl<'a> SymCacheConverter<'a> { version: crate::SYMCACHE_VERSION, debug_id: self.debug_id, - arch: self.arch, + arch: self.arch as u32, num_files, num_functions,