Skip to content

Commit 43f4851

Browse files
authored
pe.debug.POGOInfo.parse_with_opts - Possible integer overflow and out of bound memory access (#449)
Co-authored-by: BinFlip <[email protected]>
1 parent 6f3bdab commit 43f4851

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/pe/debug.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,13 +729,28 @@ impl<'a> POGOInfo<'a> {
729729
return Ok(None);
730730
}
731731

732-
if offset + idd.size_of_data as usize - POGO_SIGNATURE_SIZE > bytes.len() {
732+
if idd.size_of_data as usize <= POGO_SIGNATURE_SIZE {
733733
return Err(error::Error::Malformed(format!(
734-
"ImageDebugDirectory offset {:#x} and size {:#x} exceeds the bounds of the bytes size {:#x}",
735-
offset, idd.size_of_data, bytes.len()
734+
"ImageDebugDirectory size_of_data {:#x} is smaller or equal to POGO_SIGNATURE_SIZE {:#x}",
735+
idd.size_of_data, POGO_SIGNATURE_SIZE
736736
)));
737737
}
738-
let data = &bytes[offset..offset + idd.size_of_data as usize - POGO_SIGNATURE_SIZE];
738+
739+
let offset_end = offset.checked_add(idd.size_of_data as usize - POGO_SIGNATURE_SIZE).ok_or_else(|| {
740+
error::Error::Malformed(format!(
741+
"ImageDebugDirectory offset ({:#x}) and size ({:#x}) cause an integer overflow",
742+
offset, idd.size_of_data as usize - POGO_SIGNATURE_SIZE
743+
))
744+
})?;
745+
746+
if offset > bytes.len() || offset_end > bytes.len() {
747+
return Err(error::Error::Malformed(format!(
748+
"ImageDebugDirectory offset_start {:#x} or offset_end {:#x} exceed the bounds of the bytes size {:#x}",
749+
offset, offset_end, bytes.len()
750+
)));
751+
}
752+
753+
let data = &bytes[offset..offset_end];
739754
Ok(Some(POGOInfo { signature, data }))
740755
}
741756

0 commit comments

Comments
 (0)