Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,19 @@ mod tests {
assert!(re.is_match(b("a")).unwrap());
}

// This tests a regression caused a segfault in the pcre2 library
// https://github.com/BurntSushi/rust-pcre2/issues/10
#[test]
fn jit_test_lazy_alloc_subject() {
let subject: Vec<u8> = vec![];

let re = RegexBuilder::new()
.jit_if_available(true)
.build(r"xxxx|xxxx|xxxx")
.unwrap();
assert!(!re.is_match(&subject).unwrap());
}

#[test]
fn utf_with_invalid_data() {
let re = RegexBuilder::new()
Expand Down
12 changes: 11 additions & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,20 @@ impl MatchData {
pub unsafe fn find(
&mut self,
code: &Code,
subject: &[u8],
mut subject: &[u8],
start: usize,
options: u32,
) -> Result<bool, Error> {
// When the subject is empty, we use an empty slice
// with a known valid pointer. Otherwise, slices derived
// from, e.g., an empty `Vec<u8>` may not have a valid
// pointer, since creating an empty `Vec` is guaranteed
// to not allocate.
const EMPTY: &[u8] = &[];
if subject.is_empty() {
subject = EMPTY;
}

let rc = pcre2_match_8(
code.as_ptr(),
subject.as_ptr(),
Expand Down