Repository navigation
Conversation
Counting the strings to detect among multiple encodings used an unsigned int. The same array counted once per appearance (the recursion guard is cleared per array) could push the count to 2^32, wrapping it to 0 and under-allocating the buffers the collection pass writes into, causing a heap out-of-bounds write. Count in uint64_t so the total cannot wrap, and reject a count that would overflow the buffer allocation before allocating, matching the array_merge() element-count fix.
Contributor
|
Thanks for bringing up this issue. The |
Contributor
Author
|
It's for 32-bit: PR is mostly about hardening. I can add comment about reachability and why there is no test. |
Contributor
|
@jorgsowa OK. Well, if that's the case, then no objection. @youkidearitai, any thoughts? |
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.
Counting the strings to detect among multiple encodings used an unsigned int. The same array counted once per appearance (the recursion guard is cleared per array) could push the count to 2^32, wrapping it to 0 and under-allocating the buffers the collection pass writes into, causing a heap out-of-bounds write.
Count in
uint64_tso the total cannot wrap, and reject a count whose buffer size would overflow size_t with a warning before allocating.Regression test for the bug takes more than 60s, I'm not sure it is feasible to include it.
Triggering it requires the same array or object to be reachable from many places (copy-on-write copies, & references, or repeated object handles) so that the visit count multiplies to 2^32. Only PHP code or
unserialize()can build such a structure. Parsers like json_decode() or request parsing create a fresh value for every element.