Fix unterminated loop in parse_record#15246
Conversation
|
Thanks for the quick turnaround on this! Not fully up to speed: are there any legal situations where you can have another character directly following the record, (which is not already part of the larger lex set that was used before, (stuff like Just to make sure we are not locking out legal grammar with an invalid character error. |
|
@sholderbach I'm not super knowledgeable about the parser either, but previously, if nushell/crates/nu-parser/src/parser.rs Lines 5998 to 6002 in 122bcff So I'm pretty sure this PR should just change what error you get ("unclosed delimiter" -> "extra tokens") without changing the rules. There's the edge case of |
|
Yeah sounds like any new errors should be pretty localized with the remaining being caught further up the stack. Let's try this and see if we have any other edge-cases if they come up. (I have got to admit that I didn't grok the previous state but the more explicit state variables seem more debuggable to me :D) |
Fixes #16284 # Description #15246 happens to rely on the lexer's bug to work. Changed to a workaround solution in this PR, not sure that's good enough in terms of perf and accuracy. @ysthakur Please take your time to review the changes of `parse_record` with care. # User-Facing Changes # Tests + Formatting +1 # After Submitting
Fixes #15243
Description
As noted in #15243, a record with more characters after it (e.g.,
{a:b}/) will cause an OOM due to an infinite loop, introduced by #15023. This happens because the entire string{a:b}/is lexed as one token and passed toparse_record, where it repeatedly lexes until it hits the closing}. This PR detects such extra characters and reports an error.User-Facing Changes
{a:b}/and other such constructions will no longer cause infinite loops. Before #15023, you would've seen an "Unclosed delimiter" error message, but this PR changes that to "Invalid characters."Tests + Formatting
After Submitting