Skip to content

GH-55368: [C++][IPC] Check message type in ReadSchema - #55371

Open
professor-moody wants to merge 2 commits into
apache:mainfrom
professor-moody:fix-ipc-readschema-message-type
Open

professor-moody wants to merge 2 commits into
apache:mainfrom
professor-moody:fix-ipc-readschema-message-type

Conversation

@professor-moody

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

Copy link
Copy Markdown

Rationale for this change

The ReadSchema overload that reads from an io::InputStream checks that the message is a Schema message before decoding it, and so does UnpackSchemaMessage. The ReadSchema overload that takes a const Message& in cpp/src/arrow/ipc/reader.cc does not: it passes message.header() straight to internal::GetSchema, which casts it to a Schema table. For a RecordBatch or DictionaryBatch message the header table was verified as that type only, and reading it with the Schema accessors interprets its fields with the wrong layout. In PyArrow, read_schema in pyarrow.ipc accepts a Message and calls this overload.

What changes are included in this PR?

The const Message& overload of ReadSchema now starts with CHECK_MESSAGE_TYPE(MessageType::SCHEMA, message.type());, the same check used by the stream overload.

Are these changes tested?

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

  • ReadSchemaAcceptsSchemaMessage checks that a Schema message is still accepted and decoded to the original schema.
  • ReadSchemaRejectsNonSchemaMessage checks that RecordBatch messages (with and without body, legacy and current framing) are rejected with the same IOError message as the stream overload.

Are there any user-facing changes?

ReadSchema on a message that is not a Schema message returns an IOError instead of attempting to decode it.

This PR contains a "Critical Fix". Without it, passing a non-Schema message to this function reads its metadata with the wrong table layout.

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 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

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

@Reranko05

Copy link
Copy Markdown
Collaborator

@professor-moody Could you follow the Arrow PR template and add AI disclosure checkbox in the PR desc. Thanks!

@professor-moody

Copy link
Copy Markdown
Author

Thanks @Reranko05! Updated the PR description to follow the Arrow PR template and include the AI disclosure checkboxes.

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.

2 participants