Skip to content

Commit 9a87a99

Browse files
authored
PE: fix base relocation parser panic (#465)
* PE: fix base relocation parser panic
1 parent 0666e3f commit 9a87a99

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/pe/relocation.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,16 @@ impl<'a> RelocationData<'a> {
347347
dd.virtual_address
348348
))
349349
})?;
350+
// To allow parsing the rest, we will not raise a malformation error
351+
// when we found that the base relocation directory not lies in the binary.
352+
// If that's the case, we store an empty `bytes`, which implies no-op
353+
// when `blocks` is called.
354+
if bytes.len() < offset {
355+
return Ok(Self { bytes: &[] });
356+
}
350357
let bytes = bytes[offset..]
351-
.pread::<&[u8]>(dd.size as usize)
352-
.map_err(|_| {
353-
error::Error::Malformed(format!(
354-
"base reloc offset {:#x} and size {:#x} exceeds the bounds of the bytes size {:#x}",
355-
offset,
356-
dd.size,
357-
bytes.len()
358-
))
359-
})?;
358+
.pread_with::<&[u8]>(0, dd.size as usize)
359+
.unwrap_or_default();
360360

361361
Ok(Self { bytes })
362362
}

0 commit comments

Comments
 (0)