Repository navigation
fix(lexer): Avoid infinite loop on lone CR, U+2028 and U+2029 - #742
Open
jeff-grimes-pplx wants to merge 1 commit into
Open
jeff-grimes-pplx wants to merge 1 commit into
jeff-grimes-pplx wants to merge 1 commit into
Conversation
Since the lexer was moved to regexps in fc0a803, the directive, comment, document marker and block scalar header patterns used `.` and a multiline `$`. In JS those also treat a lone \r, U+2028 and U+2029 as line terminators, while the rest of the lexer (newline(), toLineEnd()) only breaks lines on \n and \r\n. In the stream context this matched an empty line that ended just before such a character, consumed nothing, and returned to the same state, so parsing never terminated. `YAML.parse('\u2028')`, `YAML.parse('\r')` or a leading comment line like `# note\u2028` all hung with 100% CPU. Comments after `---` and `...` were also cut short at those characters, leaking the rest of the comment into the document contents. Use `[^\n\r]|\r(?!\n)` for line content and `(?=\r?\n|$)` for line ends, matching the lexer's own line handling and the 2.x behaviour.
This branch has not been deployed
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
Lexer.lex()when a lone\r,U+2028(LS), orU+2029(PS) appears whereemptyLineOrCommentordirectiveLineis matched (e.g.YAML.parse('\u2028'),YAML.parse('\r'), orYAML.parse('# comment\u2028\nkey: value\n')).--- # commentwhen the comment contains\r,U+2028, orU+2029..and multiline$(/my) inblockScalarHeader,directiveLine,docMarker, andemptyLineOrCommentwith(?:[^\n\r]|\r(?!\n))*and(?=\r?\n|$)so they match the YAML 1.2 line-break rules used bynewline()andtoLineEnd().