-
Notifications
You must be signed in to change notification settings - Fork 163
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
Fix fail on malformed certificate table parsing #417
base: master
Are you sure you want to change the base?
Fix fail on malformed certificate table parsing #417
Conversation
2642c9f
to
2c7f7b5
Compare
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.
need some clarification on default certificate directory; also formatting things are odd
src/pe/mod.rs
Outdated
use alloc::borrow::Cow; | ||
use alloc::string::String; | ||
use alloc::vec::Vec; | ||
use core::cmp::max; |
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.
I'm surprised by these import changes, did the formatter do this?
src/pe/mod.rs
Outdated
@@ -142,7 +140,7 @@ impl<'a> PE<'a> { | |||
return Err(error::Error::Malformed(format!( | |||
"Unsupported header magic ({:#x})", | |||
magic | |||
))) | |||
))); |
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.
ditto here too, this is also surprising to me
src/pe/mod.rs
Outdated
) | ||
.unwrap_or_else(|err| { | ||
warn!("Cannot parse CertificateTable: {:?}", err); | ||
Default::default() |
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.
I can't remember, what is a default certificate directory in this case? is it going to cause other problems further down the line when parsing, or if a user accesses parts of it, will it panic? Does it have offsets into other parts of the PE file that are no longer valid, etc.?
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.
default is empty table (no certificates), so no wrong offsets there
So while this is an easy merge, I'm on the fence about whether we should; in general the malformed binary is kind of important to know, and in general, we choose to fail in those cases. However, sometimes we don't, and maybe this is one of those times, but it feels like it's just sort of skipping a malformed thing, and putting a default value in its place, which may be ok, but it also might not be. So I'd like to understand more about:
thanks for your patience! |
OK, that sounds reasonable. What if we add something like |
b94d9a3
to
ac97d4c
Compare
Hello!
In some PE files Certificate Table can be malformed / contain invalid data. But if we use
ParseOptions::parse_attribute_certificates = true
, then whole parsing is failed.I suggest use default
CertificateDirectoryTable
in case of error.