In re2/dfa.cc, the Workq::mark() method sets last_was_mark_ to false on line 391. It should set it to true. The purpose of this flag is to prevent consecutive duplicate marks from being inserted into the work queue. Because the flag is never set to true, a second call to mark() without an intervening insert() will not be deduplicated.
Code
// re2/dfa.cc:388-393
void mark() {
if (last_was_mark_)
return;
last_was_mark_ = false; // BUG: should be true
SparseSet::insert_new(nextmark_++);
}
Impact
This is a correctness bug. It affects the longest-match mode where marks are used to track match priority ordering. Duplicate marks waste mark slots and can cause the DFA to produce subtly different results than the NFA for certain patterns.
There is no memory safety issue. The SparseSet bounds check in InsertInternal (sparse_set.h:147) is active in release builds and prevents out-of-bounds access even if marks overflow.
Fix
Change line 391 from last_was_mark_ = false; to last_was_mark_ = true;
I can submit a PR to fix :)
In
re2/dfa.cc, theWorkq::mark()method setslast_was_mark_tofalseon line 391. It should set it totrue. The purpose of this flag is to prevent consecutive duplicate marks from being inserted into the work queue. Because the flag is never set totrue, a second call tomark()without an interveninginsert()will not be deduplicated.Code
Impact
This is a correctness bug. It affects the longest-match mode where marks are used to track match priority ordering. Duplicate marks waste mark slots and can cause the DFA to produce subtly different results than the NFA for certain patterns.
There is no memory safety issue. The
SparseSetbounds check inInsertInternal(sparse_set.h:147) is active in release builds and prevents out-of-bounds access even if marks overflow.Fix
Change line 391 from
last_was_mark_ = false;tolast_was_mark_ = true;I can submit a PR to fix :)