getsentry / pdb

A parser for Microsoft PDB (Program Database) debugging information
https://docs.rs/pdb/
Apache License 2.0
385 stars 69 forks source link

Small files passed into `pdb::PDB::open` return a `std::io::Error` #75

Closed schultetwin1 closed 4 years ago

schultetwin1 commented 4 years ago

If a file is less than 4096 bytes in size and past into pdb::PDB::open, the result with be a std::io::Error with ErrorKind UnexpectedEof.

An easy repro of this issue if to run the pdb_symbols example against a source file

./target/debug/examples/pdb_symbols tests/pdb_lines.rs

I would expect to get the output

error dumping PDB: UnrecognizedFileFormat

but instead I get the output

error dumping PDB: IO error while reading PDB: failed to fill whole buffer

Digging into the code a little ways it appears this happens in pdb::msf::open_msf.

https://github.com/willglynn/pdb/blob/ebaba994f28538ff8f04b9f8f5c20466621adaf2/src/msf/mod.rs#L386-L390

The call to pdb::msf::view will eventually lead to a call of read_exact with a length of 4096 which will fail since the file is not 4096 bytes long.

A quick fix to work around this, is back in pdb::msf::open_msf catch the error on the first call to view for std;:io::Error where ErrorKind is UnexpectedEof and turn that into pdb::Error::UnrecognizedFileFormat.

I have a change that does just that and will put it up for code review momentarily.