Repository navigation
check destination capacity in msgpack_vrefbuffer_migrate - #1200
Merged
redboltz merged 1 commit intoOct 30, 2026
Merged
Conversation
msgpack_vrefbuffer_migrate decided whether to grow to->array by comparing to->tail + nused against vbuf->end, the end of the source's iovec array. The two arrays are separate allocations, so the result depended on heap layout rather than on the room left in `to`. When to->array sat above the source's array the realloc was skipped and the memcpy wrote nused iovecs past to->end. Compare nused against the free slots in `to` instead. This is the C counterpart of the C++ fix in ee24845, written as a count so the check never forms a pointer past to->end. Fixes msgpack#1197.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## c_master #1200 +/- ##
============================================
+ Coverage 57.47% 61.53% +4.06%
============================================
Files 10 10
Lines 1124 1144 +20
Branches 129 140 +11
============================================
+ Hits 646 704 +58
+ Misses 478 440 -38 🚀 New features to boost your workflow:
|
Contributor
|
@rajath201 , 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.
msgpack_vrefbuffer_migratedecides whether to growto->arrayby comparingto->tail + nusedagainstvbuf->end, the end of the source's iovec array, which is a separate allocation. Whethertogrows therefore depends on heap layout: when its array sits above the source's, the realloc is skipped and thememcpywritesnusediovecs pastto->end. Two default-initialized buffers holding 20 refs each are enough for ASan to report a 320-byte heap-buffer-overflow write atvrefbuffer.c:227, the overflow described in #1197.Compare
nusedagainst the free slots into, the same fix ee24845 made to the C++vrefbuffer::migrate(), written as a count so the check never forms a pointer pastto->end(the< to->endform suggested in the issue would still only grow when there is already room). The realloc now happens exactly whentois short, so the common path does no extra work. The newvrefbuffer_c_migrate_grows_destinationtest migrates into whichever array sits higher in memory so the old check fails deterministically: on the current tree it overflows under ASan and failstail <= endwithout it, including gcc-m32, and with the fix ctest is 6/6 under clang and gcc with and without ASan/UBSan.Fixes #1197.