Fix approximately a bajillion fmt and parsing bugs

(discovered by fuzzing)

There's more to come, but this seems like a good batch for now.
This commit is contained in:
Joshua Warner 2023-01-11 19:44:29 -08:00
parent 8f62eeaf7e
commit 0b8e68f70d
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
68 changed files with 1011 additions and 229 deletions

View file

@ -290,6 +290,10 @@ fn chomp_integer_part(buffer: &[u8]) -> Result<&str, Progress> {
)
}
fn is_plausible_ident_continue(ch: char) -> bool {
ch == '_' || is_alnum(ch)
}
#[inline(always)]
fn chomp_part<F, G>(leading_is_good: F, rest_is_good: G, buffer: &[u8]) -> Result<&str, Progress>
where
@ -317,6 +321,15 @@ where
}
}
if let Ok((next, _width)) = char::from_utf8_slice_start(&buffer[chomped..]) {
// This would mean we have e.g.:
// * identifier followed by a _
// * an integer followed by an alphabetic char
if is_plausible_ident_continue(next) {
return Err(NoProgress);
}
}
if chomped == 0 {
Err(NoProgress)
} else {