-
Notifications
You must be signed in to change notification settings - Fork 171
PE: fix base relocation parser panic #465
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One worry j have is proliferation of these flags so that it overwhelms the user or has weird hard to debug affects if multiple settings are changed and they affect parsing in various hard to understand ways, but I don’t think we’re there yet (or ever will be?)
I would like to understand why the te has this set to false otherwise seems reasonable !
src/pe/mod.rs
Outdated
opts, | ||
)?); | ||
if opts.parse_basereloc { | ||
if let Some(&baserelocs_dir) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be maybe more idiomatic to write something like:
relocation_data = get_base_relocation_data().map(|dir|
RelocationData::parse(bytes, dir, etc))
Sorry for not complete example, on phone. But I think you get the gist of using map here and assigning to relocation data so the Some wraps disappear.
IMO returning an empty basereloc table in the case of the malformation would be an alternate option, but frankly, I don't like such a fail-silence design that makes debugging harder. However while I don't think basereloc malformation error is ever "useful." Should we stand by parse_basereloc flag? |
i.e., most PE parsers ignore basereloc malformation and are returning empty info |
How about we just get .reloc size from the SectionTable when reported size in DIRECTORY is invalid? |
Hi there. Thank you for your proposal. If I get your solution correct, you're ignoring the invalid range of bytes while parsing the other. That would be an option too but my concern still stands by. The concern is that whether ignoring malformations in such a way isn't a traditional way in goblin. As I mentioned previously, yet it is totally doable particularly this case however. And specifically for the binary in question, the base relocation directory is completely wrong even if some partial bytes point to the correct range of bytes. This is also my concern if this is confusing to consumers. |
@m4b I reverted the change that introduces |
The CI failure is not relevant to this change it seems (it is in ELF parser) |
can this be rebased, the CI failure was fixed |
@m4b Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
NB: non-breaking |
Found the issue on the same binary in PR below.
The base relocation directory
0xB1000..size(0xADAC)
does not exists in the binary.N.B.
This is the super "special" case where only supposed to happen in this sort of badly "packed" binaries. Proprietary linkers would usually not produce such a completely broken binaries.