jbevain / cecil

Cecil is a library to inspect, modify and create .NET programs and libraries.
MIT License
2.74k stars 624 forks source link

Fix corrupted debug header directory entry when writing multiple such entries #869

Closed vitek-karas closed 2 years ago

vitek-karas commented 2 years ago

Basically the first two entries are written correctly, and any after that which has data will have the RVA correct, but the virtual address field will be wrong. Depending on the consumer this can work (if they use RVA) or fail (if they use virtual address) as they would read garbage data.

Currently this mostly affects embedded protable PDBs since in that case we write 4 headers: CodeView, PdbChecksum, EmbeddedPdb and Deterministic (in this order), so the embedded PDB data is effectively wrong.

Also adds a test which validates that both the RVA and virtual address point to the same thing.

This fixes https://github.com/jbevain/cecil/issues/856 (I tried something very similar to the small repro posted in that issue)

/cc @tom-englert

tom-englert commented 2 years ago

:+1:

jbevain commented 2 years ago

Good catch, thanks @vitek-karas!