Skip to content
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

read: Fix subtraction overflow when Abbreviations::get is given 0 #505

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented May 14, 2020

Alternatively, we could make this take NonZeroU64 instead of u64, but those can be kind of a pain to work with.

@fitzgen fitzgen requested a review from philipc May 14, 2020 22:41
let code_usize = code as usize;
if code_usize as u64 == code && code_usize - 1 < self.vec.len() {
Some(&self.vec[code_usize - 1])
let index = (code as usize).checked_sub(1)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to try_into as well?

I also feel like we should simply use wrapping_sub here, but it probably doesn't matter. That would mean we might end up looking up a 0 in the map, but it would still be correct and this function should never be called with 0 anyway. Is this something you encountered, or are you just auditing arithmetic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something you encountered, or are you just auditing arithmetic?

Encountered during fuzzing. Not that any gimli-internal debug_info look up code was doing get(0) but the fuzz target itself did.

If we don't want this to ever be called with zero, then we should probably switch it to use NonZeroU64.

@fitzgen fitzgen force-pushed the fix-subtraction-underflow-in-abbreviations-get branch from 6755bee to 77dd16b Compare May 15, 2020 16:28
@fitzgen fitzgen force-pushed the fix-subtraction-underflow-in-abbreviations-get branch from 77dd16b to b4857f4 Compare May 18, 2020 16:46
@fitzgen fitzgen merged commit 56fb997 into gimli-rs:master May 18, 2020
@fitzgen fitzgen deleted the fix-subtraction-underflow-in-abbreviations-get branch May 18, 2020 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants