fix quadratic backtracking in timestamp parse regex#1308
Open
arib06 wants to merge 1 commit into
Open
Conversation
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.
Pull Request Checklist
toxormake testto find out!).tox -e lintormake lintto find out!).masterbranch.Description of Changes
The
Xtimestamp token uses_TIMESTAMP_RE = ^\-?\d+\.?\d+$, whose two adjacent unbounded\d+groups make the engine try every split of a digit run when the string ends in a non-digit, soparse(value, "X")on attacker-controlled input degrades to O(n^2). A ~32 KB string of digits plus one trailing character takes about 2.8s on my machine (8 KB ~0.35s, 16 KB ~1.4s), while a real timestamp parses in microseconds. The rewrite^\-?(?:\d+\.\d+|\d{2,})$accepts exactly the same strings (verified by exhaustive comparison over every string up to length 5 from{0,9,-,.}, zero differences, including the existing rejections of1565982019.and.1565982019) and matches in linear time, so the same 32 KB input now finishes in well under a millisecond.