Skip to content

Commit

Permalink
fix: Ensure we can parse Unreal4 crashes with 0-length files
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed May 9, 2022
1 parent 886f13e commit bd67086
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions symbolic-unreal/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl TryFromCtx<'_, Endian> for AnsiString {
let len = data.gread_with::<u32>(&mut offset, context)?;
let bytes = data.gread_with::<&[u8]>(&mut offset, len as usize)?;

// Convert into UTF-8 and trucate the trailing zeros
// Convert into UTF-8 and truncate the trailing zeros
let mut string = String::from_utf8_lossy(bytes).into_owned();
let actual_len = string.trim_end_matches('\0').len();
string.truncate(actual_len);
Expand Down Expand Up @@ -102,7 +102,9 @@ impl TryFromCtx<'_, usize> for Unreal4FileMeta {
};

// Ensure that the buffer contains enough data
data.gread_with::<&[u8]>(&mut offset, len)?;
if len > 0 {
data.gread_with::<&[u8]>(&mut offset, len)?;
}

Ok((file_meta, offset))
}
Expand Down

0 comments on commit bd67086

Please sign in to comment.