professor-moody opened a new pull request, #55371:
URL: https://github.com/apache/arrow/pull/55371

   # GH-55368: [C++][IPC] Check the message type in ReadSchema(const Message&)
   
   ### 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.
   
   ### AI usage
   
   This change, its test and this description were drafted with an AI coding 
assistant. The change was built and the IPC and Parquet test suites were run 
against it.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to