Skip to content
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

Non-deterministic matching starting in v1.21.2 #214

Closed
caroline-matsec opened this issue Aug 20, 2024 · 3 comments
Closed

Non-deterministic matching starting in v1.21.2 #214

caroline-matsec opened this issue Aug 20, 2024 · 3 comments
Assignees
Labels
bug A reported bug. confirmed A confirmed bug.

Comments

@caroline-matsec
Copy link

We've recently found that there are cases where the matches returned from the same exec call are non-deterministic. Sometimes a part of the result is truncated, and sometimes it returns special characters that were not in the original input string.

Here's an example script that runs the same value through 1 million times and prints when the output is unexpected. I've run this several times and have also provided some sample output below. It fails on v1.21.2 and 1.21.3, but succeeds on 1.21.1, 1.21.0 and 1.20.9.

const RE2 = require('re2');

// Regex from RFC https://www.rfc-editor.org/rfc/rfc2396#appendix-B
const URL_RFC_PATTERN = new RE2('^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?');

function parseUrl(str) {
    const matches = URL_RFC_PATTERN.exec(str);
    const rv = {
        part1: matches[2],
        part2: matches[4],
    };
    return rv;
}

for (let i = 0; i < 1000000; i++) {
    const result = parseUrl('https://my-random-example.site/');
    if (result.part1 !== 'https') {
        console.log('Unexpected result for part1 on attempt #' + i + ': ' + result.part1);
    }
    if (result.part2 !== 'my-random-example.site') {
        console.log('Unexpected result for part2 on attempt #' + i + ': ' + result.part2);
    }
}

Sample output:

$ node repro.js
Unexpected result for part1 on attempt #1396: `��)�
Unexpected result for part2 on attempt #1396: ~m-example.site
Unexpected result for part2 on attempt #2528: om-example.site
Unexpected result for part1 on attempt #844837: ���)�
Unexpected result for part2 on attempt #844837: m-example.site
@uhop uhop self-assigned this Aug 20, 2024
@uhop uhop added the bug A reported bug. label Aug 20, 2024
@uhop
Copy link
Owner

uhop commented Aug 20, 2024

Thank you for identifying the affected versions — it’ll help me to analyze the changes.

@uhop uhop added the confirmed A confirmed bug. label Aug 22, 2024
@uhop uhop closed this as completed in 0e3b06f Aug 22, 2024
@uhop
Copy link
Owner

uhop commented Aug 22, 2024

I think I fixed the problem. Please verify the fix and let me know if it works for you.

uhop added a commit that referenced this issue Aug 24, 2024
Refs #213. Refs #214. Updated deps.
@caroline-matsec
Copy link
Author

I think I fixed the problem. Please verify the fix and let me know if it works for you.

Yep, I'm no longer seeing any failures. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A reported bug. confirmed A confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants