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

   # GH-XXXXX: [C++][IPC] Validate body_length in ReadMessage and 
ReadMessageAsync
   
   ### 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.
   
   ### 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.
   
   AI assistance was used in drafting and validating this change; the patch and 
tests were reviewed and verified by the author.
   


-- 
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