Skip to content

Commit e4f7995

Browse files
committed
fix: ansi_c::undo() won't panic anymore.
1 parent 3b83847 commit e4f7995

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

gix-quote/src/ansi_c.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ pub fn undo(input: &BStr) -> Result<(Cow<'_, BStr>, usize), undo::Error> {
5151
.get(position + 1..)
5252
.ok_or_else(|| undo::Error::new("Unexpected end of input", input))?
5353
.as_bstr();
54-
let next = input[0];
54+
let next = *input
55+
.first()
56+
.ok_or_else(|| undo::Error::new("Unexpected end of input", input))?;
5557
*input = input.get(1..).unwrap_or_default().as_bstr();
5658
Ok(next)
5759
}

gix-quote/tests/quote.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,12 @@ mod ansi_c {
8080
assert_eq!(unquoted, std::borrow::Cow::Borrowed(b"hello there".as_bstr()));
8181
assert_eq!(&input[consumed..], " out of quote");
8282
}
83+
84+
#[test]
85+
fn fuzzed() {
86+
for invalid in ["\"\\", "\"Q\u{2}QT\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\0\0\\"] {
87+
assert!(ansi_c::undo(invalid.into()).is_err());
88+
}
89+
}
8390
}
8491
}

0 commit comments

Comments
 (0)