When parsing invalid ELF data with ranges larger than actual file size, CachedReader would eagerly allocate a buffer to land the read of that huge size even though the read would later fail. This could cause unbounded vec allocations. CachedReader now seeks to find the actual stream lengthh at the beginning and validates read requests against that. Also, add fuzz testing for some basic ElfStream interfaces (that's what caught this bug). Also, rustfmt the fuzz targets.
25 lines
763 B
Rust
25 lines
763 B
Rust
#![no_main]
|
|
|
|
use elf::endian::AnyEndian;
|
|
use elf::symbol::Symbol;
|
|
use elf::ElfBytes;
|
|
use libfuzzer_sys::fuzz_target;
|
|
|
|
fuzz_target!(|data: &[u8]| {
|
|
if let Ok(file) = ElfBytes::<AnyEndian>::minimal_parse(data) {
|
|
if let Ok(Some((symtab, strtab))) = file.symbol_table() {
|
|
let _: Vec<(&str, Symbol)> = symtab
|
|
.iter()
|
|
.map(|sym| (strtab.get(sym.st_name as usize).unwrap_or("unknown"), sym))
|
|
.collect();
|
|
}
|
|
|
|
if let Ok(Some((dynsym, dynstr))) = file.dynamic_symbol_table() {
|
|
let _: Vec<(&str, Symbol)> = dynsym
|
|
.iter()
|
|
.map(|sym| (dynstr.get(sym.st_name as usize).unwrap_or("unknown"), sym))
|
|
.collect();
|
|
}
|
|
}
|
|
});
|