-
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: Avoid arithmetic overflow and panics #302
Conversation
src/mach/exports.rs
Outdated
@@ -274,10 +274,16 @@ impl<'a> ExportTrie<'a> { | |||
/// Create a new, lazy, zero-copy export trie from the `DyldInfo` `command` | |||
pub fn new(bytes: &'a [u8], command: &load_command::DyldInfoCommand) -> Self { | |||
let start = command.export_off as usize; | |||
let end = (command.export_size + command.export_off) as usize; | |||
let end = start.saturating_add(command.export_size as usize); |
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.
Since this silently truncates maybe should do checked add and warn when it’s too large ? I assume this would only ever happen on a 32-bit system reading the 6GB binary ?
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 added some log::warn
for this and the FatArch
case.
This here I found via fuzzing, though the FatArch
was indeed a valid file.
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, the 16 const nit is not super important
|
||
// check the length | ||
if thread_state_bytes.len() < thread_state_byte_length { | ||
if bytes.len() < 16 + thread_state_byte_length { |
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 know you didn't introduce 16 but it might be nice to turn this into a const
since it's used again below and will be puzzling to future reviewers
thank you for adding the tests! |
The first comes from a real and valid fat file that is ~6G, the other overflow was found while fuzzing.