-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PEReader does not throw BadImageFormatException for some invalid PE files #48419
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
This is a good suggestion. Maybe we could see how the runtime or linker (or dumpbin) does it and match that algorithm here. Relevant info: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format |
I took a look at this. The reason reading the file did not fail, is that having failed to recognize the compatibility DOS header, the PE reader treated the file as a COFF file. COFF files however do not have a magic number in their header, and the ELF file was large enough to pass as having a COFF file header. I don't think there is a reliable way to detect all cases of invalid files early, and this seems to be by design; @FiniteReality something you could do is adding an |
Or, if you are certain that you are dealing with regular PE files, you can add an |
Description
Creating a
PEReader
for an invalid file type, such as an ELF can sometimes lead to a situation where thePEReader
thinks the file is valid and it will return garbage data, causing errors to occur downstream.Attached is a zipfile containing an ELF which reproduces the issue, trimmed using
dd
to reduce its filesize while still reproducing the issue.Here's the code I'm running:
Running the same code on a different ELF file throws a
BadImageFormatException
, as expected.Configuration
.NET SDK/Runtime info
The text was updated successfully, but these errors were encountered: