Skip to content

Bug: FilteredRE2::AllMatches and AllPotentials missing compiled_ check #613

@MarkLee131

Description

@MarkLee131

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions