mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 20:10:44 +00:00
Add a pe_parse cargo-fuzz target that feeds malformed bytes to ParsedPe::parse and rva_to_file_offset and, only when the summed section mapping size and SizeOfImage are at most 64 MiB, to the checked load_into_memory mapping step. No guest code is executed. Refs #157 Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
26 lines
833 B
Rust
26 lines
833 B
Rust
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
#![no_main]
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
|
|
const MAX_MAPPED_BYTES: u64 = 64 * 1024 * 1024;
|
|
|
|
fuzz_target!(|data: &[u8]| {
|
|
let Ok(pe) = xenora_loader::ParsedPe::parse(data) else {
|
|
return;
|
|
};
|
|
|
|
let _ = pe.rva_to_file_offset(pe.entry_point_rva);
|
|
let mut mapped_bytes = 0u64;
|
|
for section in &pe.sections {
|
|
let _ = pe.rva_to_file_offset(section.virtual_address);
|
|
// The loader allocates each section separately, independent of size_of_image.
|
|
let section_size = u64::from(section.virtual_size.max(section.raw_data_size));
|
|
mapped_bytes = mapped_bytes.saturating_add(section_size);
|
|
}
|
|
|
|
if mapped_bytes <= MAX_MAPPED_BYTES && u64::from(pe.size_of_image) <= MAX_MAPPED_BYTES {
|
|
let _ = pe.load_into_memory(data);
|
|
}
|
|
});
|