Skip to content

reject ext32 length 0xffffffff in the x3 parser - #1219

Merged
redboltz merged 1 commit into
msgpack:cpp_masterfrom
rajath201:x3-ext32-max-size
Nov 16, 2026
Merged

redboltz merged 1 commit into
msgpack:cpp_masterfrom
rajath201:x3-ext32-max-size

Conversation

@rajath201

Copy link
Copy Markdown

Repro: with MSGPACK_USE_X3_PARSE, msgpack::unpack(first, last) on the 8 bytes 92 c9 ff ff ff ff 01 02 returns [EXT(ptr=NULL, size=0), 2] instead of failing; calling ext.type() or streaming the object with operator<< then dereferences the null ptr (segfault on clang 23, x64).
Cause: the ext32 action in x3_parse.hpp computes the element count as _attr(ctx)+1 in 32-bit unsigned arithmetic, so a declared length of 0xffffffff wraps to 0. The parser consumes neither the type byte nor the payload, and the bytes that belong to the 4 GiB body are parsed as sibling objects. That is a framing disagreement with the regular v1/v2/v3 parsers, which either wait for the full payload or throw via check_ext_size<4>. a78b895 widened visit_ext to size_t but left this addition in 32 bits.
Fix: widen to size_t before adding one, and throw ext_size_overflow when size_t can't hold the result, the same check check_ext_size<4> does in parse.hpp. On 64-bit the short input now fails as a parse error; on 32-bit it throws ext_size_overflow. ext32_max_size_truncated fails on the current tree and passes with the fix; the rest of msgpack_x3_parse (64 cases) passes at 64 and 32 bit, with no new -Wall -Wextra -Wconversion warnings.

@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

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.91%. Comparing base (39cc081) to head (0c33574).
⚠️ Report is 40 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    #1219      +/-   ##
==============================================
- Coverage       85.36%   79.91%   -5.46%     
==============================================
  Files              80       80              
  Lines            5099     5804     +705     
  Branches          507      634     +127     
==============================================
+ Hits             4353     4638     +285     
- Misses            746     1166     +420     
🚀 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

@rajath201 , thank you for sending the PR. It looks good to me.

@redboltz
redboltz merged commit e39c1db into msgpack:cpp_master Nov 16, 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