fix: bound plain-text runs in parse_prompt_attention regex - #1919
Open
fszontagh wants to merge 2 commits into
Open
fix: bound plain-text runs in parse_prompt_attention regex#1919fszontagh wants to merge 2 commits into
fszontagh wants to merge 2 commits into
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.
Summary
parse_prompt_attentionlexes the prompt with an unbounded plain-text alternative. libstdc++'sstd::regexrecurses once per matched character, so a prompt of a few tens of kilobytes overflows the stack and segfaults before tokenization.Bound the run length. Splitting a long run is safe because the function's final pass merges adjacent segments of equal weight, and
Bis excluded from the character class, so a chunk boundary can never fall inside aBREAK.Related Issue / Discussion
None.
Additional Information
A 45KB prompt exits 139 (SIGSEGV) during tokenization before the change and completes normally after it.
Parsing results are unchanged: comparing old and new output across weighted parentheses, nested
((...)),[...], escaped\(, multipleBREAKs,BREAKINGand bareB, bare colons, the empty string, multi-byte UTF-8, and a 21KB run both bare and inside(...:1.3), every case is byte-identical.Checklist