Copilot commented on code in PR #55671:
URL: https://github.com/apache/arrow/pull/55671#discussion_r4617365435


##########
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:
   `max_metadata_length` and `max_body_length` are documented as using `-1` for 
unlimited, but every check treats any negative value as unlimited (`>= 0`). 
Thus a misconfigured value such as `-2` silently disables the protection, 
unlike `max_decompression_ratio`, which rejects values below `-1`. Please 
validate these options as `-1` or non-negative at the reader/decoder entry 
point so bounds for untrusted IPC cannot be disabled accidentally.



##########
cpp/src/arrow/ipc/reader.cc:
##########
@@ -1280,6 +1317,21 @@ Status CheckAligned(const FileBlock& block) {
   return Status::OK();
 }
 
+Status CheckBlockLimits(const FileBlock& block, const IpcReadOptions& options) 
{
+  if (options.max_metadata_length >= 0 &&
+      block.metadata_length > options.max_metadata_length) {
+    return Status::Invalid("IPC metadata length ", block.metadata_length,
+                           " exceeds maximum allowed metadata length ",
+                           options.max_metadata_length);

Review Comment:
   This helper limits only `FileBlock` metadata/body lengths. File readers load 
and verify the footer, including the embedded schema and custom metadata, in 
`ReadFooter()`/`Open()` before any `FileBlock` is processed, and that footer 
allocation is not checked against `max_metadata_length`. A hostile IPC file can 
therefore still supply an arbitrarily large footer/schema despite configuring 
the new metadata bound; either enforce the bound while reading the footer too 
or document that this option excludes file-footer metadata.



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