google / google/re2

Bug: FilteredRE2::AllMatches and AllPotentials missing compiled_ check

Open
#613 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
9.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

## Description

`FilteredRE2::FirstMatch()` checks the `compiled_` flag before proceeding and logs a `DFATAL` if `Compile()` was not called. However, `AllMatches()` and `AllPotentials()` skip this check. Calling them before `Compile()` leads to unexpected behavior because the prefilter tree has not been built.

This is the same class of bug that was fixed for `Filter.Match()` in the Python bindings (issue #484), where calling Match before Compile caused a segfault.

## Code

`FirstMatch` has the guard (line 100):
```cpp
int FilteredRE2::FirstMatch(absl::string_view text,
const std::vector& atoms) const {
if (!compiled_) {
ABSL_LOG(DFATAL) << "FirstMatch called before Compile.";
return -1;
}
...
}
```

`AllMatches` (line 112) and `AllPotentials` (line 124) lack it:
```cpp
bool FilteredRE2::AllMatches(absl::string_view text,
const std::vector& atoms,
std::vector* matching_regexps) const {
matching_regexps->clear();
// No compiled_ check here.
...
}
```

I can open a PR to submit a fix.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.