Skip to content

widen the ext allocation size in object_with_zone<type::ext> - #1230

Merged
redboltz merged 1 commit into
msgpack:cpp_masterfrom
rajath201:ext-zone-size-widen
Nov 20, 2026
Merged

redboltz merged 1 commit into
msgpack:cpp_masterfrom
rajath201:ext-zone-size-widen

Conversation

@rajath201

Copy link
Copy Markdown

Targets cpp_master. object_with_zone<msgpack::type::ext> in include/msgpack/v1/adaptor/ext.hpp sizes the zone copy as size + 1 with a uint32_t size, but msgpack::type::ext accepts a 0xffffffff-byte payload on 64-bit targets, so for the spec-maximum ext32 the sum wraps to 0 and the ptr[0] store plus memcpy(ptr + 1, v.data(), size) write 4 GiB past a zero-byte zone slot. Unpacking c9 ff ff ff ff 01 + 4 GiB with an unpack_limit that admits the maximum ext (the default 0xffffffff ext limit counts the type byte and rejects it), then as<msgpack::type::ext>() and msgpack::object(e, zone), gives an ASan heap-buffer-overflow WRITE of size 4294967295 at ext.hpp:110 into the zone's 8200-byte initial chunk.

Widen to std::size_t before adding the type byte, which is what object_with_zone<msgpack::object> already does through its size_t visit_ext; 32-bit builds are unaffected since the ext constructor caps payloads at 0xfffffffe there. It is the same wrap as #1219, but in the adaptor instead of the X3 parser, and here it corrupts the heap. I left out a committed test because reaching it needs about 8 GiB of live allocations; with the fix the reproducer completes with the payload intact, and object_with_zone, msgpack_basic, boost_variant and object pass under ASan.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.03%. Comparing base (39cc081) to head (7c70afb).
⚠️ Report is 48 commits behind head on cpp_master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff               @@
##           cpp_master    #1230      +/-   ##
==============================================
- Coverage       85.36%   80.03%   -5.34%     
==============================================
  Files              80       80              
  Lines            5099     5830     +731     
  Branches          507      645     +138     
==============================================
+ Hits             4353     4666     +313     
- Misses            746     1164     +418     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@redboltz

Copy link
Copy Markdown
Contributor

Verified on a 64 GiB machine with a real 0xffffffff-byte ext: before the patch, msgpack::object(e, zone) crashes (ASan: heap-buffer-overflow WRITE of size 4294967295 at ext.hpp:110); after it, the copy is intact and as<msgpack::type::ext>() round-trips equal. object_with_zone, msgpack_basic, boost_variant and object pass under ASan/UBSan, the header still compiles in cpp03 mode and with -m32 (where the ext constructor rejects 0xffffffff, as you say). Skipping a committed test is fine given the 8 GiB requirement.

While checking I noticed the same + 1 wrap in ext_ref (convert<ext_ref> and the ext_ref comparison operators), which makes a max-size ext convert to an empty ext_ref and compare equal to any other max-size one. That is a correctness issue rather than a memory-safety one, so it does not block this PR;

@redboltz
redboltz merged commit 0105f53 into msgpack:cpp_master Nov 20, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants