Skip to content

Commit 3fccd37

Browse files
committed
Add regression test
1 parent c300b3e commit 3fccd37

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

regex-automata/src/util/search.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,4 +1971,23 @@ mod tests {
19711971
let expected_size = 3 * core::mem::size_of::<usize>();
19721972
assert_eq!(expected_size, core::mem::size_of::<MatchErrorKind>());
19731973
}
1974+
1975+
#[test]
1976+
fn malicious_asref_guard() {
1977+
struct Bad(std::cell::Cell<bool>);
1978+
1979+
impl AsRef<[u8]> for Bad {
1980+
fn as_ref(&self) -> &[u8] {
1981+
if self.0.replace(false) {
1982+
&[]
1983+
} else {
1984+
&[0; 1000]
1985+
}
1986+
}
1987+
}
1988+
1989+
let bad = Bad(std::cell::Cell::new(true));
1990+
let input = Input::new(&bad);
1991+
assert!(input.end() <= input.haystack().len());
1992+
}
19741993
}

0 commit comments

Comments
 (0)