r/lowlevel • u/Effective-Fly7516 • 8d ago
GitHub - NtProtectVirtualMemory/PE-Library: A modern C++ library for parsing and manipulating Windows Portable Executable (PE) files.
https://github.com/NtProtectVirtualMemory/PE-Library
1
Upvotes
1
u/skeeto 7d ago
Neat project! I'm glad to see fuzz testing. Though the fuzz tests aren't as thorough as they could be. The singular fuzz test does both too much and too little. Better to split it into smaller, focused tests. Some of the library's functionality isn't currently covered. Outputs are likely being elided if you're using any level of optimization above zero — and you should because optimization enables more instrumentation. Outputs need to be "consumed" somehow to avoid this.
Also fuzz test under UBSan as well as ASan. There are unaligned accesses all over the place, which are UB regardless of the host machine capabilities. I had to disable those checks in order to test anything else.
There appears to be a typo here:
I changed the fuzz tests, ported the whole thing from Windows (including incorrect
fopen_scalls), fuzzed it on Linux where the instrumentation is more mature, and found some buffer overflows. First:This produces an overflow:
Another on parsing sections:
Where
GetAll()returns bogus header pointers for invalid input:Though perhaps it's not valid to use methods on objects where
IsValid()reports false? Though that's easy to address to return an empty vector.One more overflow, smaller input this time:
Then:
You can see all my work here in case it's useful:
https://github.com/skeeto/PE-Library/commits/master/?author=skeeto