Closed Bug 1693271 Opened 5 years ago Closed 3 years ago

Switch MatchPattern and MatchGlob to use the Rust regex engine

Categories

(WebExtensions :: General, task, P3)

task

Tracking

(firefox107 fixed)

RESOLVED FIXED
107 Branch
Tracking Status
firefox107 --- fixed

People

(Reporter: Gijs, Assigned: nika)

References

Details

Attachments

(2 files)

In bug 1691079 users reported a hang with a specific URL containing a lot of consecutive * characters that turned out to be related to an add-on (wappalyzer).

As Rob noted there:

It's not uncommon to blindly pass the URL to chrome.tabs.query without being aware of the impact of *, so we probably need to find a solution for this.

We have a TODO to consider a different regexp engine at https://searchfox.org/mozilla-central/rev/5120ec68572d946bd15101cf2ee2eaf4a210724f/toolkit/components/extensions/MatchPattern.cpp#661-663

We could probably change the replacing patterns to replace /\*+/ with .* instead of replacing each individual * to fix the impact in bug 1691079, but the example in bug 1690758 (7*7*7*...) would probably still explode the regex engine in unhelpful ways.

We could also introduce some kind of limit on the number of wildcards, or provide a separate API / opt-in to having the wildcard behaviour (and doing literal matching otherwise).

None of these ideas seem particularly appealing, so I hope that there's a better one that I'm missing...

While reading comment 0 I was 100% sure that I did already looked into this exact issue in the past and so I looked for the existing bugzilla issue:

this seems to be an exact duplicate of Bug 1570868, which is also related to a browser hang that was happening with the wapplyzer extension installed because of url that contains a lot of *.

Given that Bug 1570868 does already contain more details about the issue, it may be reasonable to keep Bug 1570868 and mark this one as a duplicate of that one.

Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE

At this point, it would probably be easy enough to switch to the Rust engine.

I fixed the simple "common" case of redundant wildcards in bug 1570868, so reopening this bug as a "use rust regex engine instead".

Status: RESOLVED → REOPENED
Resolution: DUPLICATE → ---
Summary: Figure out how to avoid accidental DoS by extensions passing URLs to `tabs.query` without escaping wildcards → Switch MatchPattern and MatchGlob tto use the rust regex engine
Summary: Switch MatchPattern and MatchGlob tto use the rust regex engine → Switch MatchPattern and MatchGlob to use the Rust regex engine
Severity: -- → N/A
Type: defect → task
Priority: -- → P3

Taking this as part of bug 1793995

Assignee: nobody → nika
Depends on: 1794001

This also involves making MatchGlob operate on UTF8String instead of DOMString,
as the rust regex crate operates on utf-8 strings. This should have no
functional impact on callers.

Depends on D158876

In debug mode, the compile for some regular expressions is much slower with the
regex crate than it was with the JS engine, likely due to the regex's crate
heavy reliance on inlining and other llvm optimizations. Subsequent runs are
much faster, as they do not need to optimize and build the DFA.

Depends on D158877

Pushed by nlayzell@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/77c06db920fe Part 1: Use RustRegex for MatchGlob, r=kmag https://hg.mozilla.org/integration/autoland/rev/8b71c15f24c7 Part 2: Fix test for slower first-run debug execution of RustRegex, r=kmag

Backed out for causing build bustages on RustRegex.h

Log tier 2: https://treeherder.mozilla.org/logviewer?job_id=392996025&repo=autoland

Flags: needinfo?(nika)
Pushed by nlayzell@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/84e7bf515c94 Part 1: Use RustRegex for MatchGlob, r=kmag https://hg.mozilla.org/integration/autoland/rev/10c5cf69b3f0 Part 2: Fix test for slower first-run debug execution of RustRegex, r=kmag

Backed out for causing build bustages

  • Backout link
  • Push with failures
  • Failure Log
  • Failure line: clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[4]: *** [/builds/worker/checkouts/gecko/config/makefiles/rust.mk:433: force-cargo-library-build] Error 101
Pushed by nlayzell@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7a62d761ebd6 Part 1: Use RustRegex for MatchGlob, r=kmag https://hg.mozilla.org/integration/autoland/rev/1f61b8f989f9 Part 2: Fix test for slower first-run debug execution of RustRegex, r=kmag
Flags: needinfo?(nika)
Pushed by csabou@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1e41b744df6b Fix for test_MatchPattern.js xpcshell failures. CLOSED TREE
Status: REOPENED → RESOLVED
Closed: 5 years ago3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 107 Branch
See Also: → 1796059
See Also: → 1696057
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: