Skip to content

Commit 329561a

Browse files
committed
fix: reproduce and fix panic when parsing integer values
Previously it would try to treat a UTF-8 string like ASCII and split the last character off, even though it wasn't always at a charcter boundary.
1 parent f89e6c4 commit 329561a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

gix-config-value/src/integer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ impl TryFrom<&BStr> for Integer {
6767
return Err(int_err(s));
6868
}
6969

70+
let last_idx = s.len() - 1;
71+
if !s.is_char_boundary(last_idx) {
72+
return Err(int_err(s));
73+
}
74+
7075
let (number, suffix) = s.split_at(s.len() - 1);
7176
if let (Ok(value), Ok(suffix)) = (number.parse(), suffix.parse()) {
7277
Ok(Self {

gix-config-value/tests/value/integer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fn invalid_from_str() {
5353
assert!(Integer::try_from(b("g")).is_err());
5454
assert!(Integer::try_from(b("123123123123123123123123")).is_err());
5555
assert!(Integer::try_from(b("gg")).is_err());
56+
assert!(Integer::try_from(b("™️🤦‍♂️")).is_err());
5657
}
5758

5859
#[test]

0 commit comments

Comments
 (0)