>>> f = Filter()
>>> f.Compile()
re2/filtered_re2.cc:74: Compile called before Add.
>>> f.Match("")
>>> f = Filter()
>>> f.Match("")
py311: exit -11
This is inside tox, using python installed with pyenv, but reproduces with both Python 3.8 and 3.11.
I would assume it's because while there is a guard to check that the filter is compiled in FirstMatch
|
if (!compiled_) { |
|
LOG(DFATAL) << "FirstMatch called before Compile."; |
|
return -1; |
|
} |
there is no such guard for
AllMatches:
|
bool FilteredRE2::AllMatches(absl::string_view text, |
|
const std::vector<int>& atoms, |
|
std::vector<int>* matching_regexps) const { |
|
matching_regexps->clear(); |
|
std::vector<int> regexps; |
|
prefilter_tree_->RegexpsGivenStrings(atoms, ®exps); |
|
for (size_t i = 0; i < regexps.size(); i++) |
|
if (RE2::PartialMatch(text, *re2_vec_[regexps[i]])) |
|
matching_regexps->push_back(regexps[i]); |
|
return !matching_regexps->empty(); |
|
} |
I assume the PrefilterTree would be the issue but apparently it guards against this
|
if (!compiled_) { |
|
// Some legacy users of PrefilterTree call Compile() before |
|
// adding any regexps and expect Compile() to have no effect. |
|
// This kludge is a counterpart to that kludge. |
|
if (prefilter_vec_.empty()) |
|
return; |
so I'm not sure why it SIGSEGVs, but I have not debugged the C++ code just looked at it.
Interestingly there is a guard in Set::Match:
|
if (!compiled_) { |
|
if (error_info != NULL) |
|
error_info->kind = kNotCompiled; |
|
LOG(DFATAL) << "RE2::Set::Match() called before compiling"; |
|
return false; |
|
} |
but
Filter::Match does not check it:
|
set_->Match(text, &atoms); |
so it does not protect the
FilteredRE2 (assuming that's what crashes, for all I know it might be something else entirely).
This is inside tox, using python installed with pyenv, but reproduces with both Python 3.8 and 3.11.
I would assume it's because while there is a guard to check that the filter is compiled in
FirstMatchre2/re2/filtered_re2.cc
Lines 96 to 99 in 108914d
AllMatches:re2/re2/filtered_re2.cc
Lines 108 to 118 in 108914d
I assume the
PrefilterTreewould be the issue but apparently it guards against thisre2/re2/prefilter_tree.cc
Lines 271 to 276 in 108914d
Interestingly there is a guard in
Set::Match:re2/re2/set.cc
Lines 128 to 133 in 108914d
Filter::Matchdoes not check it:re2/python/_re2.cc
Line 226 in 108914d
FilteredRE2(assuming that's what crashes, for all I know it might be something else entirely).