Bug: FilteredRE2::AllMatches and AllPotentials missing compiled_ check

Open Beginner friendly
#613 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
cpp
Domain
tooling

Research direction

Start with FilteredRE2::FirstMatch(), AllMatches(), and AllPotentials(), comparing the compiled_ guard in FirstMatch() with the two unchecked methods. Review the related Python binding fix in issue #484, then verify behavior when AllMatches() and AllPotentials() are called before Compile(); done means both handle that state consistently.

Written by the indexing model from the issue text.

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):

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

AllMatches (line 112) and AllPotentials (line 124) lack it:

bool FilteredRE2::AllMatches(absl::string_view text,
                             const std::vector<int>& atoms,
                             std::vector<int>* matching_regexps) const {
  matching_regexps->clear();
  // No compiled_ check here.
  ...
}

I can open a PR to submit a fix.

Dominant language
C++
Stars
9.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/re2

All issues in google/re2

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.