Skip to content

Commit

Permalink
Debug provided bytes not deserializing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Jan 20, 2023
1 parent 97ae242 commit 4b366ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/compiler/src/engine/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down
2 changes: 1 addition & 1 deletion lib/types/src/compilation/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 10 additions & 4 deletions lib/types/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -205,6 +205,7 @@ impl MetadataHeader {

/// Parses the header and returns the length of the metadata following it.
pub fn parse(bytes: &[u8]) -> Result<usize, DeserializeError> {
println!("parsing metadata header...");
if bytes.as_ptr() as usize % 8 != 0 {
return Err(DeserializeError::CorruptedBinary(
"misaligned metadata".to_string(),
Expand All @@ -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)
}
}

0 comments on commit 4b366ef

Please sign in to comment.