Skip to content

[Bug]: Playing Error : :hover/g: Regular expression too large #1675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
EricLLLLLL opened this issue Apr 8, 2025 · 0 comments · May be fixed by #1681
Open
1 task done

[Bug]: Playing Error : :hover/g: Regular expression too large #1675

EricLLLLLL opened this issue Apr 8, 2025 · 0 comments · May be fixed by #1681
Labels
bug Something isn't working

Comments

@EricLLLLLL
Copy link

Preflight Checklist

  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

What package is this bug report for?

rrweb-snapshot

Version

2.0.0-alpha.18

Expected Behavior

Correctly handle regular expressions that are too long

Actual Behavior

rule.selectors.forEach(function (selector) {
if (selector.includes(':hover')) {
rule.selector += ',\n' + selector.replace(/:hover/g, '.\:hover');
}
});

  1. When CSS selectors are very long or complex, the engine may run out of memory
  2. ​Dynamically modify rule.selector in a loop: the array will grow dynamically, leading to an ​infinite loop​;
    ​Duplicate processing: even fixed rules will be reprocessed.
  3. Double backslash \ is parsed as a single \ in CSS, resulting in an invalid class name .:hover

Steps to Reproduce

const generateKillerCSS = (length) => {

let selector = '';
for (let i = 0; i < length; i++) {
selector += .class-${i}:hover:not([data-${i % 100}="${'x'.repeat(50)}"]),;
}
return selector.slice(0, -1);
};

const dangerousCSS = generateKillerCSS(50000);

try {
const regex = /:hover/g;
const result = dangerousCSS.replace(regex, '\:hover');
} catch (e) {
console.error( e.message);
}

Testcase Gist URL

No response

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment