Closed Bug 1640479 Opened 5 years ago Closed 4 years ago

Named capture groups left undefined after OOM in RegExpShared::initializeNamedCaptures

Categories

(Core :: JavaScript Engine, defect, P1)

defect

Tracking

()

RESOLVED FIXED
mozilla78
Tracking Status
firefox78 --- fixed

People

(Reporter: anba, Assigned: iain)

References

Details

Attachments

(1 file)

Test case:

var i = 0;
oomTest(function() {
    for (var j = 0; j < 20; ++j) {
        var r = RegExp(`(?<_${(i++).toString(32)}a>)`);
        try { var e = r.exec("a"); } catch {}
        if (e && e.groups === undefined) print("bad groups");
        try { var e = r.exec("a"); } catch {}
        if (e && e.groups === undefined) print("bad groups");
    }
});

Expected:

  • Doesn't print "bad groups"

Actual:

  • Prints "bad groups"

This happens after OOM in RegExpShared::initializeNamedCaptures: RegExpShared::kind_ is already set to RegExpShared::Kind::RegExp by the earlier call to RegExpShared::useRegExpMatch, so we don't try to recompile the pattern to compute the groups for the second exec call.

Iain, could take a look at this bug.

Severity: -- → S3
Flags: needinfo?(iireland)
Priority: -- → P1

If we throw an OOM in initializeNamedCaptures for a RegExpShared, we will set kind to RegExp, but not initialize the named captures data. If we recover from the OOM and then execute the same regexp, the cached RegExpShared will not be reparsed, and we won't create named captures for it.

The fix is to reorder CompilePattern so that we only change the state of the RegExpShared after all of the initialization has succeeded. initializeNamedCaptures already avoids this problem by saving the updates until the end.

Depends on D76956

Assignee: nobody → iireland
Status: NEW → ASSIGNED
Flags: needinfo?(iireland)
Pushed by iireland@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2a44daf61d7f Don't set kind if initializeNamedCaptures fails r=mgaudet
Flags: needinfo?(andrebargull) → needinfo?(iireland)
Flags: needinfo?(iireland)

Forgot to make the testcase conditional on oomTest being defined.

Pushed by iireland@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/13469bdc290b Don't set kind if initializeNamedCaptures fails r=mgaudet
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla78
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: