Skip to content

Commit

Permalink
fix: prevent underflows while trying to abs() very large numbers.
Browse files Browse the repository at this point in the history
For example, "@{-9223372036854775808}" could trigger a panic previously,
but now it will do the right thing.
  • Loading branch information
Byron committed Oct 26, 2023
1 parent c197cbf commit 9b1a575
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gix-revision/src/spec/parse/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ where
if n < 0 {
if name.is_empty() {
delegate
.nth_checked_out_branch(n.abs().try_into().expect("non-negative isize fits usize"))
.nth_checked_out_branch(n.unsigned_abs())
.ok_or(Error::Delegate)?;
} else {
return Err(Error::RefnameNeedsPositiveReflogEntries { nav: nav.into() });
Expand Down
7 changes: 7 additions & 0 deletions gix-revision/tests/spec/parse/anchor/at_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ fn braces_must_be_closed() {
}
}

#[test]
#[cfg_attr(target_pointer_width = "32", ignore = "Only works this way on 64 bit systems")]
fn fuzzed() {
let rec = parse("@{-9223372036854775808}");
assert_eq!(rec.nth_checked_out_branch, [Some(9223372036854775808), None]);
}

#[test]
fn reflog_by_entry_for_current_branch() {
for (spec, expected_entry) in [("@{0}", 0), ("@{42}", 42), ("@{00100}", 100)] {
Expand Down

0 comments on commit 9b1a575

Please sign in to comment.