fix: in lib/json in json.c#7
Closed
orbisai0security wants to merge 1 commit into
Closed
Conversation
Automated security fix generated by Orbis Security AI
Contributor
|
Close in favor of #11 |
Author
|
Thanks, that makes sense. I missed that the parser already bounds count via JSON_CONTAINER_MAX before these copies. The static_assert approach is cleaner since it documents and enforces the no-overflow invariant without adding unreachable runtime checks. Appreciate the attribution in #11. |
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
Fix critical severity security issue in
lib/json.c.Vulnerability
V-004lib/json.c:279Description: In lib/json.c at lines 279 and 354, size calculations of the form count * sizeof(struct ...) are used to determine both allocation sizes and memcpy lengths. If count is attacker-controlled (e.g., from a JSON array length field) and is set near SIZE_MAX / sizeof(struct json_value), the multiplication wraps to a small value. The allocator creates an undersized buffer based on the wrapped value, and the subsequent memcpy writes the full (large) number of bytes, overflowing the undersized buffer and corrupting heap memory.
Changes
lib/json.cVerification
Automated security fix by OrbisAI Security
Summary by cubic
Fixes a critical integer overflow in
lib/json.cthat could under-allocate buffers and corrupt heap memory when parsing large arrays or objects. We now validate element counts before allocation and memcpy.count > SIZE_MAX / sizeof(...)).JSON_ERR_OVERFLOWinstead of allocating/copying when the count is unsafe.Written for commit 837ee16. Summary will update on new commits.