moyix / pdbparse

Python code to parse Microsoft PDB files
Other
316 stars 84 forks source link

Missing IMAGE_SECTION_HEADER or GlobalsData breaks parsing #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Using pdbparse 1.0 and construct 2.5.0 on Python 2.7.4, I had a few issues 
loading some PDB files. One of the issue was already reported in ticket #8 and 
fixed in trunk.

The other two issues are both with some Windows 7 PDB files not containing 
something pdbparse expects.

Trying to load EA23305E14F24F9F837CCEACEE5D38401\fastfat.pdb, I got a construct 
exception about the number of IMAGE_SECTION_HEADER structs not being in the 
acceptable range because there are none.

Trying to load F8E2A8B5C9B74BF4A6E4A48F180099942\ntkrnlmp.pdb, I got a 
construct exception about the number of GlobalsData structs not being in the 
acceptable range because there are none.

I was able to solve both by replacing GreedyRange with OptionalGreedyRange. 
After making those two modifications and applying the fix for #8, I was able to 
load all the PDB files I needed.

A patch for pe.py and gdata.py is attached.

Original issue reported on code.google.com by kichik on 11 Apr 2013 at 2:51

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r103.

Original comment by moo...@gmail.com on 11 Apr 2013 at 3:41

GoogleCodeExporter commented 9 years ago
It appears this issue is a bit more complicated than I thought. Parsing these 
PDB files alone doesn't cause any issue. My original patch should probably be 
reverted.

This issue only happens if a few PDB files are parsed in the same process. 
Parsing the same PDB in an endless loop doesn't trigger the issue. Parsing a 
few of them in a loop does trigger the issue pretty reliably.

Using `reload(pdbparse)` after one of the exceptions seems to temporarily 
resolve the issue until it goes bad again. That seems to suggest a global is 
being corrupted, but I couldn't find any globals in the code.

From some debugging I've done, it seems like something in the PDB is being 
skipped. When the section headers failed to load, it was because the data being 
parsed from them was from 0x1000, even though the section headers are at 0x8000.

I've attached a script that reproduce this issue pretty reliably. I tested this 
with:

* Windows 7 x64
* Python 2.7.3
* Construct 2.5.0
* pdbparse 1.0

Original comment by kichik on 15 Apr 2013 at 5:27

Attachments:

GoogleCodeExporter commented 9 years ago
Could you make sure you are trying this with the most recent SVN version of 
pdbparse (and that there aren't any old ones hanging around on your system)? I 
have had your repro script running for 1.5 hours without seeing any failures. 
There was a problem with global state being corrupted, but it was fixed back in 
r87.

Original comment by moo...@gmail.com on 16 Apr 2013 at 11:37

GoogleCodeExporter commented 9 years ago
It works perfectly fine with the latest SVN version for me too. I wrongly 
assumed latest SVN version will not fix this because there was no closed issue 
for it. Sorry for the waste of time. 

Original comment by kichik on 16 Apr 2013 at 11:49

GoogleCodeExporter commented 9 years ago
Fixed back in r87. Sorry for not creating an issue for it at the time; I tend 
to use the issue tracker just for externally-reported bugs.

Original comment by moo...@gmail.com on 17 Apr 2013 at 4:47