Copilot commented on code in PR #55671:
URL: https://github.com/apache/arrow/pull/55671#discussion_r4614480791
##########
cpp/src/arrow/ipc/reader.cc:
##########
@@ -576,12 +581,35 @@ Result<std::shared_ptr<Buffer>> DecompressBuffer(const
std::shared_ptr<Buffer>&
return SliceBuffer(buf, sizeof(int64_t), compressed_size);
}
+ if (compressed_size == 0 && uncompressed_size > 0) {
+ return Status::Invalid(
+ "Compressed buffer has 0 payload bytes but non-zero uncompressed size
",
+ uncompressed_size);
+ }
+
+ if (options.max_decompression_ratio > 0) {
Review Comment:
The documented unlimited sentinel is `-1`, so `0` should be a valid limit
that rejects any positive expansion. With this `> 0` guard, setting
`max_decompression_ratio = 0` disables the check entirely and an arbitrarily
large `uncompressed_size` is still allocated. Apply the ratio check for
non-negative limits (and reject other negative values if they are not intended).
##########
cpp/src/arrow/ipc/options.h:
##########
@@ -189,6 +189,15 @@ struct ARROW_EXPORT IpcReadOptions {
/// The lazy property will always be reset to true to deliver the expected
behavior
io::CacheOptions pre_buffer_cache_options = io::CacheOptions::LazyDefaults();
+ /// \brief Maximum allowed metadata length in bytes (-1 means unlimited).
+ int64_t max_metadata_length = -1;
+
+ /// \brief Maximum allowed body length in bytes (-1 means unlimited).
+ int64_t max_body_length = -1;
+
+ /// \brief Maximum allowed decompression expansion ratio (-1 means
unlimited).
+ int32_t max_decompression_ratio = -1;
Review Comment:
`IpcReadOptions` is also used by `RecordBatchFileReader`, but these limits
are only consumed by the new `StreamDecoder` constructor. The file-reader paths
still call `ReadMessage(..., options.memory_pool)` / `ReadMessageAsync(...,
options.memory_pool)` (and the cached-source path uses the default decoder), so
a configured `max_metadata_length` or `max_body_length` is silently ignored for
IPC files and can still permit the untrusted lengths to drive reads and
allocations. Please thread the full options through all file/message-reader
paths or enforce these limits before reading the blocks.
--
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]