Conversation
`parse_str` only clears the key buffer right before copying an escaped key into it. A key with a simple escape (`\f`, `\n`, `\`) therefore leaves its unescaped bytes behind, and when a later borrowed key (or a later array element) leads into `get_many_keys`, the `debug_assert!(strbuf.is_empty())` there fires. Release builds return the right result, but any caller testing with debug assertions panics on such input. Clear the buffer on entry to `get_many_keys` instead of asserting it is empty; nothing reads a key's bytes past its own lookup. Fixes cloudwego#241
|
|
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.
Fixes #241.
parse_stronly clears the key buffer right before it copies an escaped key into it. A key with a simple escape (\f,\n,\) leaves its unescaped bytes in the buffer, and whenget_many_keysis entered again with that buffer,debug_assert!(strbuf.is_empty())fires. There are two ways to get there:{"\f":9,"c":{"d":1}}withc/d, as in the issue{"a":[{"x":1,"\f":2},{"y":3}]}witha/0/xanda/1/yClearing the buffer only before the recursion in
get_many_keyswould miss the second case, so this clears it on entry toget_many_keysin place of the assert. Nothing reads a key's bytes after its own lookup, so the result is unchanged. Release builds were already returning the right values.Added
test_get_many_after_escaped_keycovering both cases forget_manyandget_many_unchecked. It panics onmainwith debug assertions and passes with the fix.cargo testandcargo clippy --all-targets --all-features -- -D warningspass locally.