Skip to content

fix: Reject lengths whose buffer sizes overflow int64 in minimal validation - #988

Merged
paleolimbot merged 3 commits into
apache:mainfrom
pedrobtz:fix-validate-size-overflow
Nov 6, 2026
Merged

paleolimbot merged 3 commits into
apache:mainfrom
pedrobtz:fix-validate-size-overflow

Conversation

@pedrobtz

Copy link
Copy Markdown
Contributor

ArrowArrayViewValidateMinimal() checks that offset + length fits an int64_t, then multiplies it by the element size to get each buffer's minimum size. For a fixed-size list it multiplies by the list size to get the child's minimum length. Neither product is checked. A large length overflows the product, which is undefined behaviour. In practice it wraps, and can wrap to a small size that then passes. For an int32 array of length 2^62 + 1, 32 * 4611686018427387905 overflows. Without this change, validation returns NANOARROW_OK with a 16-byte data buffer.

The length is now checked against each buffer's element size in bits before any size is computed, with room for the round-up to whole bytes. It is also checked against the list size before the fixed-size list child length is computed. Lengths that fit behave as before.

The new ArrayViewTestBufferSizeOverflow test validates both cases at the minimal level and expects EINVAL. Without the fix, UBSan reports the overflow and the int32 case returns NANOARROW_OK.

Found by fuzzing the IPC reader in the zuarrow R package, which vendors nanoarrow. An IPC field node can declare any length, and ArrowIpcArrayStreamReader reached this overflow at full validation.

ctest passes in a plain Debug build and with ASan and UBSan (410 tests each). The changed files are formatted with the pinned clang-format 16.0.6.

🤖 Generated with Claude Code

…dation

The minimum buffer sizes and the fixed-size list child length were
computed by multiplying offset + length without an overflow check, so a
huge length could wrap around to a small size and pass validation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.46%. Comparing base (5ca4bcf) to head (b0064e0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #988      +/-   ##
==========================================
- Coverage   78.47%   78.46%   -0.02%     
==========================================
  Files         106      106              
  Lines       17230    17239       +9     
  Branches     2064     2064              
==========================================
+ Hits        13522    13527       +5     
- Misses       2446     2450       +4     
  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 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!

# Conflicts:
#	src/nanoarrow/common/array_test.cc
@paleolimbot
paleolimbot merged commit d643716 into apache:main Nov 6, 2026
43 of 44 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