Skip to content

MINOR: [C++][IPC] Validate ReadMessage body_length - #55382

Open
professor-moody wants to merge 2 commits into
apache:mainfrom
professor-moody:fix-ipc-readmessage-body-length
Open

professor-moody wants to merge 2 commits into
apache:mainfrom
professor-moody:fix-ipc-readmessage-body-length

Conversation

@professor-moody

@professor-moody professor-moody commented Nov 3, 2026 •

Copy link
Copy Markdown

Rationale for this change

The ReadMessage overload that takes a body_length and ReadMessageAsync in cpp/src/arrow/ipc/message.cc read metadata_length + body_length bytes with a single read and then give the first metadata_length bytes to the message decoder. Nothing checks body_length: a negative value makes the read shorter than metadata_length while the metadata slice keeps its full length (the only consistency check in ReadMessageContinued is a DCHECK_EQ), and a large value overflows the sum. RecordBatchFileReader validates footer blocks in FileBlockFromFlatbuffer before calling these functions, but other callers of these public functions get no such check.

What changes are included in this PR?

ReadMessageInternal and ReadMessageAsync return Status::Invalid when body_length is negative or when metadata_length + body_length would overflow int64_t, before any IO is issued.

Are these changes tested?

Yes, in cpp/src/arrow/ipc/message_internal_test.cc (MessageDecodingTest fixture):

  • ReadMessageValidBodyLength reads the sample messages with their actual body length through ReadMessage and ReadMessageAsync and checks the returned body length.
  • ReadMessageInvalidBodyLength checks that body lengths of -1, -8 and INT64_MAX are rejected with Invalid by both functions.

Are there any user-facing changes?

Invalid body_length arguments return Invalid. Valid calls are unaffected.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@github-actions github-actions Bot added the awaiting review Awaiting review label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Thanks for opening a pull request!

This pull request has been automatically converted to a draft because its title doesn't match Arrow's required format.

If this is not a minor PR, could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

After updating the title, you can mark the pull request as ready for review.

See also:

@github-actions
github-actions Bot marked this pull request as draft November 3, 2026 20:46
@professor-moody professor-moody changed the title GH-XXXXX: [C++][IPC] Validate ReadMessage body_length MINOR: [C++][IPC] Validate ReadMessage body_length Nov 3, 2026
@professor-moody
professor-moody marked this pull request as ready for review November 3, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant