fix(core): harden writer and node growth paths against integer overflow#120
Open
ngoyal88 wants to merge 2 commits intoludocode:developfrom
Open
fix(core): harden writer and node growth paths against integer overflow#120ngoyal88 wants to merge 2 commits intoludocode:developfrom
ngoyal88 wants to merge 2 commits intoludocode:developfrom
Conversation
Guard `used + count` and resize doubling arithmetic in `mpack_growable_writer_flush()` to prevent `size_t` wraparound. Return `mpack_error_memory` on unrepresentable growth requests instead of entering unsafe/non-terminating resize behavior.
…ation Prevent `size_t` wraparound in tree parsing/accounting paths by validating arithmetic before use: - guard `data_length + bytes` checks in reserve/growth logic - guard `node_count + total` against max node limit overflow - guard dynamic page allocation size computation for child nodes Fail safely with existing MPack error paths (`mpack_error_too_big` / `mpack_error_memory`) instead of relying on wrapped arithmetic.
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.
PR Description
Summary
src/mpack/mpack-writer.c.src/mpack/mpack-node.c.Problem
Both writer growth and node parsing/allocation paths used unchecked
size_tarithmetic in boundary-sensitive code.With extreme input sizes, this can cause wraparound and lead to incorrect bounds decisions, allocation-size corruption, or non-terminating growth behavior.
Changes
src/mpack/mpack-writer.cused + countbefore growth computations.mpack_error_memorywhen growth target is not representable.src/mpack/mpack-node.cnode_count + totalagainstmax_nodes.total - 1multiplier path).Validation
Risk
Low. Changes are localized, minimal, and only affect overflow-edge arithmetic and error handling paths.