Skip to content

Commit 4fc3a1b

Browse files
parser: if closing square bracket not found, stop looking for it again
This solves #5584, where the fuzzing would take hours without this.
1 parent 09048a3 commit 4fc3a1b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/uucore/src/lib/parser/parse_glob.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ fn fix_negation(glob: &str) -> String {
1818
while i + 3 < chars.len() {
1919
if chars[i] == '[' && chars[i + 1] == '^' {
2020
match chars[i + 3..].iter().position(|x| *x == ']') {
21-
None => (),
21+
None => {
22+
// if closing square bracket not found, stop looking for it
23+
// again
24+
break;
25+
}
2226
Some(j) => {
2327
chars[i + 1] = '!';
2428
i += j + 4;
@@ -90,6 +94,11 @@ mod tests {
9094
assert_eq!(fix_negation("[[]] [^a]"), "[[]] [!a]");
9195
assert_eq!(fix_negation("[[] [^a]"), "[[] [!a]");
9296
assert_eq!(fix_negation("[]] [^a]"), "[]] [!a]");
97+
98+
// test that we don't look for closing square brackets unnecessarily
99+
// Verifies issue #5584
100+
let teststring = std::iter::repeat("^[").take(174571).collect::<String>();
101+
assert_eq!(fix_negation(teststring.as_str()), teststring);
93102
}
94103

95104
#[test]

0 commit comments

Comments
 (0)