Regex query can lead to a crash in SBE

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Query Execution
    • Fully Compatible
    • ALL
    • QE 2026-05-25, QE 2026-06-08
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The following query can leads to an invariant failure in debug build and can lead to seg fault in release build.

      assert.commandWorked(db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "trySbeEngine"}));
      const coll = db[jsTestName()];
      coll.drop();
      assert.commandWorked(coll.insert({s: ""}));
      coll.aggregate([\{$project: {r: {$regexFindAll: {input: "$s", regex: "a*"}}}}]) 

      This happens when the regex pattern matches at the end of the input string (https://github.com/10gen/mongo/blob/69bbbf7992cdaeb91a28e26d3d88ce0e40434d4f/src/mongo/db/exec/sbe/vm/vm_builtin_regex.cpp#L234) 

      So it would also reproduce with input being any string and regex pattern being "$".

      In debug build,  StringData::operator[] checks the pos and trips an invariant. Since all string types in sbe are null terminated this won't lead to a crash in release variant.

            Assignee:
            Projjal Chanda
            Reporter:
            Projjal Chanda
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: