Skip to content

fix: Reject message sizes that overflow the header size - #984

Merged
paleolimbot merged 2 commits into
apache:mainfrom
pedrobtz:fix-ipc-header-size-overflow
Nov 11, 2026
Merged

paleolimbot merged 2 commits into
apache:mainfrom
pedrobtz:fix-ipc-header-size-overflow

Conversation

@pedrobtz

Copy link
Copy Markdown
Contributor

ArrowIpcDecoderReadHeaderPrefix() adds the 4- or 8-byte prefix to the message size read from the input, and stores the sum in the int32_t decoder->header_size_bytes. A message size near INT32_MAX overflows that sum, which is undefined behaviour. UBSan reports it as signed integer overflow: 8 + 2147483647 cannot be represented in type 'int32_t'. The size is now checked for that overflow before it is added. The negative-size check moves first, so it still runs before the sum.

The new NanoarrowIpcCheckHeaderSizeOverflow test peeks a header with size INT32_MAX after the continuation marker, and a pre-0.15 header with size INT32_MAX - 3. Both now return EINVAL. Without the fix, the test fails under UBSan at the addition.

The input was found by fuzzing the IPC reader in the zuarrow R package, which vendors nanoarrow.

ctest passes with ASan and UBSan (410 tests). The changed files are formatted with the pinned clang-format 16.0.6.

🤖 Generated with Claude Code

@codecov-commenter

codecov-commenter commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.52%. Comparing base (08d23f6) to head (297b2ba).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #984   +/-   ##
=======================================
  Coverage   78.52%   78.52%           
=======================================
  Files         106      106           
  Lines       17195    17199    +4     
  Branches     2064     2065    +1     
=======================================
+ Hits        13502    13506    +4     
  Misses       2431     2431           
  Partials     1262     1262           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paleolimbot

Copy link
Copy Markdown
Member

@pedrobtz I've updated CI to fix the failures. Can you rebase or merge the latest main into your PRs? I'll re-run CI on them and work through them over the next few days.

A message size near INT32_MAX overflowed decoder->header_size_bytes
when the 4- or 8-byte prefix was added to it. Check it before adding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pedrobtz
pedrobtz force-pushed the fix-ipc-header-size-overflow branch from 955651a to 93d2209 Compare October 22, 2026 15:27
@pedrobtz

Copy link
Copy Markdown
Contributor Author

Thanks! I've rebased all seven onto main (55df060): #984, #985, #986, #987, #988, #989 and #990. Each still passes ctest locally with ASan and UBSan.

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@paleolimbot paleolimbot changed the title fix(ipc): Reject message sizes that overflow the header size fix: Reject message sizes that overflow the header size Nov 11, 2026
@paleolimbot
paleolimbot merged commit 807a001 into apache:main Nov 11, 2026
42 checks passed
paleolimbot pushed a commit that referenced this pull request Nov 17, 2026
…ooter (#1014)

Fixes #1013

The footer size check in ArrowIpcDecoderVerifyFooter() and
ArrowIpcDecoderDecodeFooter() adds the header size, sizeof(int32_t) and
the magic length in size_t and stores the result in an int32_t.
ArrowIpcDecoderPeekFooter() only rejects negative footer sizes, so a
footer size near INT32_MAX (for example 0x7FFFFFFE) makes the sum wrap
to a negative value. The ESPIPE check then passes, and the footer
pointer ends up about 2 GiB past the end of the buffer, which
VerifyFooter and DecodeFooter then read.

This change:
- Computes the sum as int64_t in both functions, and prints it with
PRId64 in the VerifyFooter message.
- Adds to ArrowIpcDecoderDecodeFooter() the same ESPIPE check that
VerifyFooter() has, before the footer pointer is computed.
DecodeFooter() had no size check, so it now returns ESPIPE for short
input instead of reading past the buffer.

The approach matches the message header fix in #984 and the check in
ArrowIpcDecoderDecodeHeader().

Testing:
- New test NanoarrowIpcTest.NanoarrowIpcFooterSizeOverflow
(src/nanoarrow/ipc/decoder_test.cc): a 16-byte buffer with footer size
0x7FFFFFFE. It checks that VerifyFooter() returns ESPIPE with the
expected message, and that DecodeFooter() returns ESPIPE after
PeekFooter().
- Ran with the CMake build: nanoarrow_ipc_decoder_test passes. The new
test passes with the fix and fails without it.

- clang-format 16.0.6 (--dry-run --Werror) and codespell 2.2.5 on the
changed files: clean.

Not run: the full ctest suite, `pre-commit run --all-files`, and the
Meson CI job.
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