-
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
PE: Change Section Table Real Name Handling #438
base: master
Are you sure you want to change the base?
PE: Change Section Table Real Name Handling #438
Conversation
@@ -76,7 +76,9 @@ impl SectionTable { | |||
table.characteristics = bytes.gread_with(offset, scroll::LE)?; | |||
|
|||
if let Some(idx) = table.name_offset()? { | |||
table.real_name = Some(bytes.pread::<&str>(string_table_offset + idx)?.to_string()); | |||
if let Ok(real_name) = bytes.pread::<&str>(string_table_offset + idx) { | |||
table.real_name = Some(real_name.to_string()); |
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 think it would be more idiomatic to do:
table.real_name = bytes.pread::<&str>(string_table_offset + idx).ok().map(String::to_owned);
the real question is whether:
- It should be considered a fatal error if the name is not utf8
- we should log on error, in which case keeping the
if let Ok
is better
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.
Sorry it took me so long to reply!
As far as I understand, real_name
is stored in COFF String Table, but there is nothing stated about the encoding. However? for Symbol Name the following is stated:
By convention, the names are treated as zero-terminated UTF-8 encoded strings.
Maybe, it can be applied to real_name
, too?
However, I do not consider it to be a fatal error, so maybe we should stick to if let Ok
?
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.
yes i think it's ok; the idiomatic suggestion above i wrote is a if let Ok
that (ok()
maps Result to Option, and then map
returns the owned portion if it is some); my only question was whether we should log it or not. if we log it then putting it in a let ok is better. i'll leave it up to you which to do, e.g.:
- do the single line ok map
- do if let with logging on failure side.
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.
as suggested, just needs tiny fixup then ready to go, thank you for this!
@@ -76,7 +76,9 @@ impl SectionTable { | |||
table.characteristics = bytes.gread_with(offset, scroll::LE)?; | |||
|
|||
if let Some(idx) = table.name_offset()? { | |||
table.real_name = Some(bytes.pread::<&str>(string_table_offset + idx)?.to_string()); | |||
if let Ok(real_name) = bytes.pread::<&str>(string_table_offset + idx) { | |||
table.real_name = Some(real_name.to_string()); |
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.
yes i think it's ok; the idiomatic suggestion above i wrote is a if let Ok
that (ok()
maps Result to Option, and then map
returns the owned portion if it is some); my only question was whether we should log it or not. if we log it then putting it in a let ok is better. i'll leave it up to you which to do, e.g.:
- do the single line ok map
- do if let with logging on failure side.
Excuse me for interrupting. I encountered the similar thing before and this is the minimum reproducible test case I wrote that time. Perhaps adding some kind of tests for such would be awesome and hope it helps!
|
While trying to parse a particular PE file, I stumbled across an
"invalid utf8"
error coming from Section Table Real Name. However hard I tried I couldn't find the problem with the file itself. But this simple change in the source code ofparse()
function finally worked.