Repository navigation
Guard msgpack_zone_init chunk allocation against wraparound - #1206
Merged
Merged
Conversation
init_chunk_list() in src/zone.c now rejects a chunk_size for which sizeof(msgpack_zone_chunk) + chunk_size wraps, so msgpack_zone_init() and msgpack_zone_new() fail instead of allocating a tiny chunk. Add a test.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## c_master #1206 +/- ##
============================================
+ Coverage 57.47% 62.66% +5.18%
============================================
Files 10 10
Lines 1124 1149 +25
Branches 129 141 +12
============================================
+ Hits 646 720 +74
+ Misses 478 429 -49 🚀 New features to boost your workflow:
|
Contributor
|
@jimaf Thank you for sending the PR. It looks good to me. |
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.
init_chunk_list() in src/zone.c, which msgpack_zone_init() and msgpack_zone_new() call, computes malloc(sizeof(msgpack_zone_chunk) + chunk_size) without a wraparound check. This adds the check and returns false, the same as the existing malloc failure path, so msgpack_zone_init() returns false and msgpack_zone_new() returns NULL. It follows the wrap guard approach #1191 used for msgpack_zone_malloc_expand() and the other growth paths.
Testing
Reproduction
Before this change, an ASan harness that passes a chunk size in [SIZE_MAX-7, SIZE_MAX] (64-bit) directly to msgpack_zone_init() or msgpack_zone_new() reports a heap-buffer-overflow WRITE of size 8 into the undersized chunk. After the change both calls fail cleanly with no sanitizer output. I did not demonstrate a path where untrusted input reaches this in a stock build, and the library's own callers in src/unpack.c pass the default MSGPACK_ZONE_CHUNK_SIZE, so this is a defensive guard.
This change was prepared with help from Anthropic's Claude (AI assistance). I reviewed the change; the tests were run in Docker as described above.