From 4b366ef2d479568da7530aa944b73f551bfa346b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 20 Jan 2023 16:29:23 +0100 Subject: [PATCH] Debug provided bytes not deserializing correctly --- lib/compiler/src/engine/artifact.rs | 6 +++--- lib/types/src/compilation/symbols.rs | 2 +- lib/types/src/serialize.rs | 14 ++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/compiler/src/engine/artifact.rs b/lib/compiler/src/engine/artifact.rs index 2c917475273..07c4c23c60f 100644 --- a/lib/compiler/src/engine/artifact.rs +++ b/lib/compiler/src/engine/artifact.rs @@ -106,9 +106,9 @@ impl Artifact { eprintln!("Could not deserialize as static object: {}", err); } } - return Err(DeserializeError::Incompatible( - "The provided bytes are not wasmer-universal".to_string(), - )); + return Err(DeserializeError::Incompatible(format!( + "Artifact::deserialize: The provided bytes are not wasmer-universal" + ))); } let bytes = Self::get_byte_slice(bytes, ArtifactBuild::MAGIC_HEADER.len(), bytes.len())?; diff --git a/lib/types/src/compilation/symbols.rs b/lib/types/src/compilation/symbols.rs index 81bd8d5ceb7..195f355f787 100644 --- a/lib/types/src/compilation/symbols.rs +++ b/lib/types/src/compilation/symbols.rs @@ -123,7 +123,7 @@ impl ModuleMetadata { ) -> Result<&ArchivedModuleMetadata, DeserializeError> { if metadata_slice.len() < 8 { return Err(DeserializeError::Incompatible( - "invalid serialized ModuleMetadata".into(), + "ModuleMetadata::archive_from_slice: invalid serialized ModuleMetadata".into(), )); } let mut pos: [u8; 8] = Default::default(); diff --git a/lib/types/src/serialize.rs b/lib/types/src/serialize.rs index 44d051b6418..0b0f76aa954 100644 --- a/lib/types/src/serialize.rs +++ b/lib/types/src/serialize.rs @@ -168,7 +168,7 @@ impl SerializableModule { /// Metadata header which holds an ABI version and the length of the remaining /// metadata. #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Debug, Copy)] pub struct MetadataHeader { magic: [u8; 8], version: u32, @@ -205,6 +205,7 @@ impl MetadataHeader { /// Parses the header and returns the length of the metadata following it. pub fn parse(bytes: &[u8]) -> Result { + println!("parsing metadata header..."); if bytes.as_ptr() as usize % 8 != 0 { return Err(DeserializeError::CorruptedBinary( "misaligned metadata".to_string(), @@ -217,18 +218,23 @@ impl MetadataHeader { })? .try_into() .unwrap(); + + println!("bytes: {:?}", bytes); let header: Self = unsafe { mem::transmute(bytes) }; + println!("header {:#?}", header); if header.magic != Self::MAGIC { return Err(DeserializeError::Incompatible( - "The provided bytes were not serialized by Wasmer".to_string(), + "MetadataHeader::parse: The provided bytes were not serialized by Wasmer" + .to_string(), )); } + println!("header ok!"); if header.version != Self::CURRENT_VERSION { return Err(DeserializeError::Incompatible( - "The provided bytes were serialized by an incompatible version of Wasmer" - .to_string(), + format!("MetadataHeader::parse: The provided bytes were serialized by an incompatible version of Wasmer: expected version {}, got version {}", Self::CURRENT_VERSION, header.version) )); } + println!("metadata parsing ok!"); Ok(header.len as usize) } }