Skip to content

GH-55400: [C++][IPC] Validate body_length in ReadMessage and ReadMessageAsync - #55401

Closed
ShivanshhhG wants to merge 1 commit into
apache:mainfrom
ShivanshhhG:fix-55400-ipc-validate-body-length
Closed

ShivanshhhG wants to merge 1 commit into
apache:mainfrom
ShivanshhhG:fix-55400-ipc-validate-body-length

Conversation

@ShivanshhhG

Copy link
Copy Markdown

Rationale for this change

In ipc::ReadMessage(offset, metadata_length, body_length, file) and ipc::ReadMessageAsync, body_length is added to metadata_length to issue a single IO read for the entire message buffer. However, body_length was not validated before issuing the read:

  1. Negative body_length values caused ReadAt / ReadAsync to read fewer bytes than metadata_length, but SliceBuffer(metadata, 0, metadata_length) still sliced using the expected length, resulting in out-of-bounds reads during decoding.
  2. Extremely large body_length values could overflow 64-bit signed integer addition (metadata_length + body_length).

What changes are included in this PR?

  • Validates that body_length >= 0 in ReadMessageInternal (when body_length is provided) and ReadMessageAsync.
  • Uses internal::AddWithOverflow to guard against arithmetic overflow when adding metadata_length + body_length.
  • Returns Status::Invalid if validation fails.
  • Adds regression unit tests in cpp/src/arrow/ipc/read_write_test.cc verifying invalid and overflowing body_length are rejected in both synchronous and asynchronous overloads.

Are these changes tested?

Yes, covered by unit tests in cpp/src/arrow/ipc/read_write_test.cc (TestReadMessage.ReadBodyWithInvalidLength).

Are there any user-facing changes?

Direct calls to ipc::ReadMessage and ipc::ReadMessageAsync with negative or overflowing body_length now return Status::Invalid instead of proceeding with invalid buffer reads.

…adMessageAsync

Validate that body_length is non-negative and does not overflow signed 64-bit integer addition when added to metadata_length in ReadMessageInternal and ReadMessageAsync before issuing reads.

Closes apache#55400.

Signed-off-by: SHIVANSH-ux-ys <singaser78@gmail.com>
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Thanks for opening a pull request!

This pull request has been automatically closed because you currently have 4 open pull requests, which is more than the limit of 3.

Due to the increase in pull requests opened by AI bots, and in order to keep the review queue manageable, Apache Arrow limits contributors without repository access to at most 3 concurrently open pull requests. This helps make sure each pull request gets the attention it needs and that work in progress does not go stale.

Once one of your other open pull requests has been merged or closed, you are welcome to reopen this one.

See also:

@github-actions github-actions Bot closed this Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #55400 has been automatically assigned in GitHub to PR creator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant