Skip to content

Commit 9b1a575

Browse files
committed
fix: prevent underflows while trying to abs() very large numbers.
For example, "@{-9223372036854775808}" could trigger a panic previously, but now it will do the right thing.
1 parent c197cbf commit 9b1a575

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

gix-revision/src/spec/parse/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ where
422422
if n < 0 {
423423
if name.is_empty() {
424424
delegate
425-
.nth_checked_out_branch(n.abs().try_into().expect("non-negative isize fits usize"))
425+
.nth_checked_out_branch(n.unsigned_abs())
426426
.ok_or(Error::Delegate)?;
427427
} else {
428428
return Err(Error::RefnameNeedsPositiveReflogEntries { nav: nav.into() });

gix-revision/tests/spec/parse/anchor/at_symbol.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ fn braces_must_be_closed() {
1010
}
1111
}
1212

13+
#[test]
14+
#[cfg_attr(target_pointer_width = "32", ignore = "Only works this way on 64 bit systems")]
15+
fn fuzzed() {
16+
let rec = parse("@{-9223372036854775808}");
17+
assert_eq!(rec.nth_checked_out_branch, [Some(9223372036854775808), None]);
18+
}
19+
1320
#[test]
1421
fn reflog_by_entry_for_current_branch() {
1522
for (spec, expected_entry) in [("@{0}", 0), ("@{42}", 42), ("@{00100}", 100)] {

0 commit comments

Comments
 (0)