Skip to content

Bug: Workq::mark() sets last_was_mark_ to false instead of true #611

@MarkLee131

Description

@MarkLee131

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

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