JS/Python: Fix FP in redos related to empty lookaheads#6288
Merged
erik-krogh merged 7 commits intogithub:mainfrom Aug 16, 2021
Merged
JS/Python: Fix FP in redos related to empty lookaheads#6288erik-krogh merged 7 commits intogithub:mainfrom
erik-krogh merged 7 commits intogithub:mainfrom
Conversation
Contributor
|
LGTM I think it would be worth adding some test cases with a lookahead that just checks for an anchor, without an alternative that is also empty. That's one of the main cases where /(x*)+(?=$)/
/(x*)+(?=$|y)/
/([\s\S]*)+(?=$)/
/([\s\S]*)+(?=$|y)/ |
asgerf
reviewed
Jul 16, 2021
Comment on lines
+376
to
+377
| var bad91 = /([\s\S]*)+(?=$)/ | ||
| var bad92 = /([\s\S]*)+(?=$|y)/ No newline at end of file |
Contributor
There was a problem hiding this comment.
I believe the last two ones should be marked as good? I'm not asking for the query to handle them, just that the test is accurate.
Contributor
Author
There was a problem hiding this comment.
You're right. I was a little fast there.
Contributor
Author
asgerf
previously approved these changes
Aug 12, 2021
yoff
requested changes
Aug 16, 2021
Contributor
yoff
left a comment
There was a problem hiding this comment.
Just one thing to address. I also wonder if matchesEpsilon would be nicer as a member predicate on RegExpTerm, but I will not insist on that for this PR.
Co-authored-by: yoff <lerchedahl@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5964
Lookaheads/lookbehinds that match the empty string will always match, and they are thus pretty much useless and unnecessary.
However, I've now seen multiple regular expressions that have empty lookaheads.
The ReDoS query assumed that a lookahead had a rejecting suffix, but that assumptions breaks with lookaheads that match the empty string.
This PR fixes that by adding an epsilon transition across lookaheads/lookbehinds that match the empty string.
JavaScript evaluation looks fine
Python evaluation looks fine
I don't think this needs a change-note.