Repository navigation
[#22709][fix] MuseSpark tool parser: scan a whitespace run once in the header patterns #22711
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
LeizhenZhang
wants to merge
2
commits into
NVIDIA:main
Choose a base branch
from
LeizhenZhang:fix/musespark-whitespace-runs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+190
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a streaming regression test for the
_HEADER_TAIL_REwhitespace boundary.The new timing tests call
detect_and_parse, which uses only_HEADER_RE. The streaming test at lines 593-612 countssearchcalls and recorded lengths, not regex work. Removing(?<!\s)from_HEADER_TAIL_REwould therefore pass all existing tests.Add a test that streams a long whitespace run through the tail search. For example, deliver
"set to=x" + " " * 100_000 + "done."throughparse_streaming_increment, then assert that the result has no calls, the normal text is preserved, and the elapsed time stays under the bound used by the timing test. Confirm that this input reaches the tail search through_may_hold_header. Place the test next totest_musespark_header_patterns_are_linear_in_a_whitespace_run.ast-grep (0.51.1)
[warning] 143-143: Regex pattern passed to re is built from a non-literal (variable, call, concatenation, or f-string) value. If that value is attacker-controlled it can introduce a malicious pattern with catastrophic backtracking (ReDoS). Use a hardcoded literal pattern, or validate/escape untrusted input with re.escape() and bound the regex complexity before compiling.
Context: re.compile(r"(?:<|start|>assistant\s+|(?<!\s)\s+)to=" + _NAME + r"\s*$")
Note: [CWE-1333] Inefficient Regular Expression Complexity.
(redos-non-literal-regex-python)
Source: Path instructions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Added in 7f83da9 as
test_musespark_held_header_tail_is_linear_in_a_whitespace_run.It streams
"set to=x" + " " * 100_000 + "done."throughparse_streaming_incrementin 4-character deltas. The parser holds the text fromto=xon, so_HEADER_TAIL_REsearches the held run. The test wraps the pattern and asserts that the longest text it searched is over 100,000 characters, so the boundary is really exercised. It then checks that there are no calls, that the normal text equals the input, and that the stream finishes within the existing 5 s bound.With
(?<!\s)removed from_HEADER_TAIL_REand everything else from the follow-up kept, the test fails after 84.6 s:On 3ab2658 it fails too, after 116.5 s, because each delta still rescanned the held run (your second comment). With the follow-up as committed it passes. The 7 new test cases of this commit take 1.81 s together.