Skip to content

Commit

Permalink
Accept populated COFF symbol headers
Browse files Browse the repository at this point in the history
Some binaries may hade pointers to COFF symbols that point to nothing.
Since COFF symbols tables are deprecated anyway, they can be ignored.
  • Loading branch information
daladim committed Dec 17, 2021
1 parent e45a3d1 commit 21a851c
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/read/coff/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,36 @@ where
impl<'data, R: ReadRef<'data>> SymbolTable<'data, R> {
/// Read the symbol table.
pub fn parse(header: &pe::ImageFileHeader, data: R) -> Result<Self> {
// The symbol table may not be present.
// According to MS, "COFF debugging information is deprecated", so these may not be present
let mut offset = header.pointer_to_symbol_table.get(LE).into();
let (symbols, strings) = if offset != 0 {
let symbols = data
.read_slice(&mut offset, header.number_of_symbols.get(LE) as usize)
.read_error("Invalid COFF symbol table offset or size")?;

// Note: don't update data when reading length; the length includes itself.
let length = data
.read_at::<U32Bytes<_>>(offset)
.read_error("Missing COFF string table")?
.get(LE);
let str_end = offset
.checked_add(length as u64)
.read_error("Invalid COFF string table length")?;
let strings = StringTable::new(data, offset, str_end);

(symbols, strings)
} else {
(&[][..], StringTable::default())
if offset == 0 {
return Ok(SymbolTable {
symbols: &[][..],
strings: StringTable::default(),
});
}

let symbols = match data.read_slice(&mut offset, header.number_of_symbols.get(LE) as usize)
{
Ok(sybls) => sybls,
Err(_) => {
return Ok(SymbolTable {
symbols: &[][..],
strings: StringTable::default(),
})
}
};

// Note: don't update data when reading length; the length includes itself.
let length = data
.read_at::<U32Bytes<_>>(offset)
.read_error("Missing COFF string table")?
.get(LE);
let str_end = offset
.checked_add(length as u64)
.read_error("Invalid COFF string table length")?;
let strings = StringTable::new(data, offset, str_end);

Ok(SymbolTable { symbols, strings })
}

Expand Down

0 comments on commit 21a851c

Please sign in to comment.