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


##########
arrow-ipc/src/compression.rs:
##########
@@ -413,6 +427,26 @@ mod tests {
         assert_eq!(input_bytes, result.as_slice());
     }
 
+    #[test]
+    #[cfg(feature = "lz4")]
+    fn test_lz4_decompression_rejects_output_exceeding_advertised_size() {

Review Comment:
   nice



##########
arrow-ipc/src/compression.rs:
##########
@@ -375,14 +386,17 @@ fn decompress_zstd(
     ))
 }
 
-/// Get the uncompressed length
-/// Notes:
-///   LENGTH_NO_COMPRESSED_DATA: indicate that the data that follows is not 
compressed
-///    0: indicate that there is no data
-///   positive number: indicate the uncompressed length for the following data
-/// Returns an error if the input buffer is shorter than 8 bytes
+/// Reads the uncompressed length from a compressed IPC buffer.
+///
+/// A positive value is the exact expected uncompressed length, `0` indicates
+/// that there is no data, and `-1` indicates that the bytes following the
+/// prefix are not compressed.
+/// IPC decompression limits its output buffer to a positive advertised length
+/// and rejects output whose length differs.
+///
+/// Returns an error if the input buffer is shorter than the 8-byte prefix.
 #[inline]
-fn read_uncompressed_size(buffer: &[u8]) -> Result<i64, ArrowError> {
+pub fn read_uncompressed_size(buffer: &[u8]) -> Result<i64, ArrowError> {

Review Comment:
   >  where instead of unconditionally doing decompress and possibly getting an 
OOM issue during the allocation, you check if resources (memory in this case) 
in your system are available and make a decision based on that. 
   
   this is interesting, you may be interested in this issue 
https://github.com/apache/arrow-rs/issues/10392



##########
arrow-ipc/src/compression.rs:
##########


Review Comment:
   while we're here can we avoid this panic? it should be pretty 
straightforward to error here.



##########
arrow-ipc/src/compression.rs:
##########
@@ -375,14 +386,17 @@ fn decompress_zstd(
     ))
 }
 
-/// Get the uncompressed length
-/// Notes:
-///   LENGTH_NO_COMPRESSED_DATA: indicate that the data that follows is not 
compressed
-///    0: indicate that there is no data
-///   positive number: indicate the uncompressed length for the following data
-/// Returns an error if the input buffer is shorter than 8 bytes
+/// Reads the uncompressed length from a compressed IPC buffer.
+///
+/// A positive value is the exact expected uncompressed length, `0` indicates
+/// that there is no data, and `-1` indicates that the bytes following the
+/// prefix are not compressed.
+/// IPC decompression limits its output buffer to a positive advertised length
+/// and rejects output whose length differs.
+///
+/// Returns an error if the input buffer is shorter than the 8-byte prefix.
 #[inline]
-fn read_uncompressed_size(buffer: &[u8]) -> Result<i64, ArrowError> {
+pub fn read_uncompressed_size(buffer: &[u8]) -> Result<i64, ArrowError> {

Review Comment:
   makes sense, I'm interested in what Jefffrey thinks.
   
   



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