Rich-T-kid commented on code in PR #12077:
URL: https://github.com/apache/arrow-rs/pull/12077#discussion_r4472591500


##########
arrow-ipc/src/compression.rs:
##########
@@ -274,6 +280,17 @@ impl CompressionCodec {
         decompressed_size: usize,
         context: &mut DecompressionContext,
     ) -> Result<Vec<u8>, ArrowError> {
+        let (max_expansion_ratio, codec_name) = match self {
+            CompressionCodec::Lz4Frame => (LZ4_MAX_EXPANSION_RATIO, "LZ4"),
+            CompressionCodec::Zstd(_) => (ZSTD_MAX_EXPANSION_RATIO, "ZSTD"),
+        };
+        // Refuse a size the input cannot expand to before allocating for it.
+        if decompressed_size > input.len().saturating_mul(max_expansion_ratio) 
{
+            return Err(ArrowError::IpcError(format!(
+                "Advertised decompressed size of {decompressed_size} exceeds 
what {} bytes of {codec_name} data can expand to",
+                input.len()
+            )));
+        }

Review Comment:
   If the issue is allocating too much memory up front, wouldn’t it be simpler 
to cap the initial allocation and let the vector grow as needed?



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