You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "azecevic000 (via GitHub)" <gi...@apache.org> on 2026/09/02 16:58:54 UTC

[PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

azecevic000 opened a new pull request, #10959:
URL: https://github.com/apache/arrow-rs/pull/10959

   # Rationale for this change
   
   Compressed Arrow IPC buffers advertise their uncompressed length in an 8-byte prefix. `decompress_to_buffer` interprets `0` as empty, `-1` as uncompressed, and a positive value as the expected decompressed length. For a positive value, IPC decompression already requires an exact match: the common codec path rejects a returned buffer whose length differs from the advertised length.
   
   The codecs previously differed in how they used this value while decompressing. ZSTD passes it as the output capacity to an API that returns an error if the decompressed data exceeds that capacity. LZ4, however, used it only as the initial `Vec` capacity before an unbounded `read_to_end`, allowing Arrow's output `Vec` to grow beyond the advertised length before the final check.
   
   This change gives both codecs the same output-size invariants:
   
   - No more than the advertised number of decompressed bytes are accumulated in the output `Vec`.
   - Successful decompression returns exactly the advertised number of bytes.
   
   Without the LZ4 bound, an untrusted compressed stream could cause Arrow's output `Vec` to grow beyond an accepted advertised length before decompression eventually failed. With the bound, the potentially unbounded output accumulation is limited to the advertised length.
   
   Downstream IPC consumers may also need to inspect the advertised length before decompression so that they can reject an unreasonable value before allocating the output buffer. Exposing `read_uncompressed_size` lets them do so without duplicating Arrow's interpretation of the IPC prefix.
   
   # What changes are included in this PR?
   
   - Publicly re-export `read_uncompressed_size` from `arrow-ipc` and document the `-1`, `0`, and positive-length semantics.
   - Limit the Arrow-owned LZ4 output buffer to the advertised length while decompressing, and reject output that exceeds it without growing that buffer.
   - Correct the existing length-mismatch error message to refer to the decompressed length.
   
   The advertised length remains the exact required output length on successful return and bounds the number of decompressed bytes accumulated in Arrow's output `Vec`. It does not bound the compressed input, allocator overhead, or codec working memory.
   
   # Are these changes tested?
   
   No new tests are introduced. Existing tests cover successful LZ4 and ZSTD round trips and rejection of prefixes shorter than 8 bytes. The new LZ4 over-limit rejection is not directly covered.
   
   # Are there any user-facing changes?
   
   Yes. `arrow_ipc::read_uncompressed_size` is a new public, non-breaking API that lets callers inspect the IPC compression prefix before decompression.
   
   Malformed LZ4 input whose decompressed output exceeds its advertised length is now rejected before Arrow's output buffer grows beyond that length. Valid IPC input is unaffected.
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r4067636590


##########
arrow-ipc/src/compression.rs:
##########
@@ -375,21 +386,27 @@ 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> {
     let len_buffer = buffer.get(..LENGTH_OF_PREFIX_DATA as usize).ok_or_else(|| {
         ArrowError::IpcError(format!(
             "Compressed IPC buffer is too short: expected at least {LENGTH_OF_PREFIX_DATA} bytes, got {}",
             buffer.len()
         ))
     })?;
-    Ok(i64::from_le_bytes(len_buffer.try_into().unwrap()))
+    let len_buffer: [u8; 8] = len_buffer
+        .try_into()
+        .map_err(|e| ArrowError::IpcError(format!("Invalid uncompressed length prefix: {e}")))?;

Review Comment:
   would prefer to revert in this case, to avoid confusion in there potentially being a reachable error here



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "azecevic000 (via GitHub)" <gi...@apache.org>.
azecevic000 commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r4065925979


##########
arrow-ipc/src/compression.rs:
##########
@@ -375,21 +386,27 @@ 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> {
     let len_buffer = buffer.get(..LENGTH_OF_PREFIX_DATA as usize).ok_or_else(|| {
         ArrowError::IpcError(format!(
             "Compressed IPC buffer is too short: expected at least {LENGTH_OF_PREFIX_DATA} bytes, got {}",
             buffer.len()
         ))
     })?;
-    Ok(i64::from_le_bytes(len_buffer.try_into().unwrap()))
+    let len_buffer: [u8; 8] = len_buffer
+        .try_into()
+        .map_err(|e| ArrowError::IpcError(format!("Invalid uncompressed length prefix: {e}")))?;

Review Comment:
   Not really with the current implementation. I believe this was asked by @Rich-T-kid here https://github.com/apache/arrow-rs/pull/10959#discussion_r3919451723. I don't have a strong opinion here, I can revert it to the previous state if you would prefer that.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#issuecomment-5514154446

   🤖 Arrow criterion benchmark completed (GKE) | [trigger](https://github.com/apache/arrow-rs/pull/10959#issuecomment-5513931990)
   
   **Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB)
   
   Comparing ipc-decompression-size-upper-bound (eb92502eb182f5ecafa25fa03117f1bfa03e289f) to b84fc5c (merge-base) [diff](https://github.com/apache/arrow-rs/compare/b84fc5cfa9bbc8698d2487a444c6baaa489351f7..eb92502eb182f5ecafa25fa03117f1bfa03e289f)
   
   <details><summary>Run configuration</summary>
   
   ```yaml
   run benchmark ipc_reader
   ```
   
   </details>
   
   <details><summary>CPU Details (lscpu)</summary>
   
   ```
   Architecture:                            aarch64
   CPU op-mode(s):                          64-bit
   Byte Order:                              Little Endian
   CPU(s):                                  16
   On-line CPU(s) list:                     0-15
   Vendor ID:                               ARM
   Model name:                              Neoverse-V2
   Model:                                   1
   Thread(s) per core:                      1
   Core(s) per cluster:                     16
   Socket(s):                               -
   Cluster(s):                              1
   Stepping:                                r0p1
   BogoMIPS:                                2000.00
   Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
   L1d cache:                               1 MiB (16 instances)
   L1i cache:                               1 MiB (16 instances)
   L2 cache:                                32 MiB (16 instances)
   L3 cache:                                80 MiB (1 instance)
   NUMA node(s):                            1
   NUMA node0 CPU(s):                       0-15
   Vulnerability Gather data sampling:      Not affected
   Vulnerability Indirect target selection: Not affected
   Vulnerability Itlb multihit:             Not affected
   Vulnerability L1tf:                      Not affected
   Vulnerability Mds:                       Not affected
   Vulnerability Meltdown:                  Not affected
   Vulnerability Mmio stale data:           Not affected
   Vulnerability Reg file data sampling:    Not affected
   Vulnerability Retbleed:                  Not affected
   Vulnerability Spec rstack overflow:      Not affected
   Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
   Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
   Vulnerability Spectre v2:                Mitigation; CSV2, BHB
   Vulnerability Srbds:                     Not affected
   Vulnerability Tsa:                       Not affected
   Vulnerability Tsx async abort:           Not affected
   Vulnerability Vmscape:                   Not affected
   ```
   
   </details>
   
   <details><summary>Details</summary>
   <p>
   
   ```
   group                                                       ipc-decompression-size-upper-bound     main
   -----                                                       ----------------------------------     ----
   arrow_ipc_reader/FileReader/no_validation/read_10           1.00    118.4±5.47µs        ? ?/sec    1.04    122.6±6.16µs        ? ?/sec
   arrow_ipc_reader/FileReader/no_validation/read_10/mmap      1.00     59.0±0.79µs        ? ?/sec    1.00     58.8±0.90µs        ? ?/sec
   arrow_ipc_reader/FileReader/read_10                         1.00   423.1±38.69µs        ? ?/sec    1.00   424.5±34.62µs        ? ?/sec
   arrow_ipc_reader/FileReader/read_10/mmap                    1.00   482.1±35.99µs        ? ?/sec    1.01   487.1±34.93µs        ? ?/sec
   arrow_ipc_reader/StreamReader/no_validation/read_10         1.00    118.3±4.62µs        ? ?/sec    1.02    120.8±4.85µs        ? ?/sec
   arrow_ipc_reader/StreamReader/no_validation/read_10/zstd    1.00      2.5±0.02ms        ? ?/sec    1.00      2.4±0.02ms        ? ?/sec
   arrow_ipc_reader/StreamReader/read_10                       1.00   426.5±37.64µs        ? ?/sec    1.00   425.1±42.45µs        ? ?/sec
   arrow_ipc_reader/StreamReader/read_10/zstd                  1.00      2.7±0.01ms        ? ?/sec    1.00      2.7±0.01ms        ? ?/sec
   ```
   
   </p>
   </details>
   
   <details><summary>Resource Usage</summary>
   
   **base (merge-base)**
   | Metric | Value |
   |--------|-------|
   | Wall time | 85.0s |
   | Peak memory | 16.4 MiB |
   | Avg memory | 12.1 MiB |
   | CPU user | 71.9s |
   | CPU sys | 10.1s |
   | Peak spill | 0 B |
   
   **branch**
   | Metric | Value |
   |--------|-------|
   | Wall time | 85.0s |
   | Peak memory | 15.8 MiB |
   | Avg memory | 11.1 MiB |
   | CPU user | 69.4s |
   | CPU sys | 9.6s |
   | Peak spill | 0 B |
   </details>
   
   
   ---
   [File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#issuecomment-5513537087

   🤖 Arrow criterion benchmark running (GKE) | [trigger](https://github.com/apache/arrow-rs/pull/10959#issuecomment-5513518595)
   **Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB) | `Linux bench-c5513518595-2087-kkkx4 6.12.94+ #1 SMP Fri Jul 17 09:42:57 UTC 2026 aarch64 GNU/Linux`
   <details><summary>CPU Details (lscpu)</summary>
   
   ```
   Architecture:                            aarch64
   CPU op-mode(s):                          64-bit
   Byte Order:                              Little Endian
   CPU(s):                                  16
   On-line CPU(s) list:                     0-15
   Vendor ID:                               ARM
   Model name:                              Neoverse-V2
   Model:                                   1
   Thread(s) per core:                      1
   Core(s) per cluster:                     16
   Socket(s):                               -
   Cluster(s):                              1
   Stepping:                                r0p1
   BogoMIPS:                                2000.00
   Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
   L1d cache:                               1 MiB (16 instances)
   L1i cache:                               1 MiB (16 instances)
   L2 cache:                                32 MiB (16 instances)
   L3 cache:                                80 MiB (1 instance)
   NUMA node(s):                            1
   NUMA node0 CPU(s):                       0-15
   Vulnerability Gather data sampling:      Not affected
   Vulnerability Indirect target selection: Not affected
   Vulnerability Itlb multihit:             Not affected
   Vulnerability L1tf:                      Not affected
   Vulnerability Mds:                       Not affected
   Vulnerability Meltdown:                  Not affected
   Vulnerability Mmio stale data:           Not affected
   Vulnerability Reg file data sampling:    Not affected
   Vulnerability Retbleed:                  Not affected
   Vulnerability Spec rstack overflow:      Not affected
   Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
   Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
   Vulnerability Spectre v2:                Mitigation; CSV2, BHB
   Vulnerability Srbds:                     Not affected
   Vulnerability Tsa:                       Not affected
   Vulnerability Tsx async abort:           Not affected
   Vulnerability Vmscape:                   Not affected
   ```
   
   </details>
   
   Comparing ipc-decompression-size-upper-bound (eb92502eb182f5ecafa25fa03117f1bfa03e289f) to b84fc5c (merge-base) [diff](https://github.com/apache/arrow-rs/compare/b84fc5cfa9bbc8698d2487a444c6baaa489351f7..eb92502eb182f5ecafa25fa03117f1bfa03e289f)
   
   <details><summary>Run configuration</summary>
   
   ```yaml
   run benchmark arrow-ipc
   ```
   
   </details>
   
   BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow-ipc
   Results will be posted here when complete
   
   ---
   [File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "azecevic000 (via GitHub)" <gi...@apache.org>.
azecevic000 commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r3923982634


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


Review Comment:
   Sure, done.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Limit LZ4 buffer to declared decompressed size [arrow-rs]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey merged PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "azecevic000 (via GitHub)" <gi...@apache.org>.
azecevic000 commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r3924067141


##########
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:
   Thanks for pointing out the issue, though the proposition is more about memory optimization if some kind of projection is done (which I agree can be significant for some workloads), the issue I raised is more concerned with having a guaranteed upper bound on memory allocation and knowing it before allocation happens.
   
   Thanks for the review, I totally understand general hesitation when expansion of the public API surface area is considered. In this case, though, I believe the decompressed size is more than internal detail, as downstream users can generally make decisions based on it.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "Rich-T-kid (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r4067633319


##########
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:
   > By staying private, any downstream user that would mimic this function would depend on a lot of implementation details that might change in the future (its first 8 bytes, its little-endian, etc.)
   
   given its part of the IPC format specification, its more than a private implementation detail anyway



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "azecevic000 (via GitHub)" <gi...@apache.org>.
azecevic000 commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r4070146727


##########
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:
   Reverted `pub` change, only LZ4 fix remains in this PR.
   
   > given its part of the IPC format specification, its more than a private implementation detail anyway
   
   Yeah, you're right, being part of the specification (with trivial implementation) makes this a non-issue, as even if a major version upgrade of the specification happens, it will surely have to provide backwards compatibility for quite some time.
   
   > what I would ideally want is an API that gives me an uncompressed size of the whole RecordBatch
   
   I guess the specification also makes this kind of computation stable and not reliant on implementation details (arguably this might change it https://github.com/apache/arrow-rs/issues/10392), though it's not trivial, so when I have some initial proposition (hopefully by the end of the week), I will share it, and we can discuss if you see the value in taking the ownership of this kind of API.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "azecevic000 (via GitHub)" <gi...@apache.org>.
azecevic000 commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r4070037845


##########
arrow-ipc/src/compression.rs:
##########
@@ -375,21 +386,27 @@ 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> {
     let len_buffer = buffer.get(..LENGTH_OF_PREFIX_DATA as usize).ok_or_else(|| {
         ArrowError::IpcError(format!(
             "Compressed IPC buffer is too short: expected at least {LENGTH_OF_PREFIX_DATA} bytes, got {}",
             buffer.len()
         ))
     })?;
-    Ok(i64::from_le_bytes(len_buffer.try_into().unwrap()))
+    let len_buffer: [u8; 8] = len_buffer
+        .try_into()
+        .map_err(|e| ArrowError::IpcError(format!("Invalid uncompressed length prefix: {e}")))?;

Review Comment:
   Sure, done.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "Rich-T-kid (via GitHub)" <gi...@apache.org>.
Rich-T-kid commented on PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#issuecomment-5513518595

   run benchmark arrow-ipc


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "azecevic000 (via GitHub)" <gi...@apache.org>.
azecevic000 commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r3917704450


##########
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:
   @Rich-T-kid Thank you for the prompt review. I have added a test that returns an error on an underreported size for LZ4.
   
   To answer your question, this function can be very useful for downstream users. It allows effective resource governance, 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. That is also why LZ4 fix is important, since it gives us a much stronger guarantee.
   
   I don't see any other way to achieve this currently that is exposed through the public API.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Limit LZ4 buffer to declared decompressed size [arrow-rs]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#issuecomment-5788611996

   thanks @azecevic000 & @Rich-T-kid 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "Rich-T-kid (via GitHub)" <gi...@apache.org>.
Rich-T-kid commented on PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#issuecomment-5513931990

   run benchmark ipc_reader


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#issuecomment-5514112697

   🤖 Arrow criterion benchmark running (GKE) | [trigger](https://github.com/apache/arrow-rs/pull/10959#issuecomment-5513931990)
   **Instance:** `c4a-highmem-16` (12 vCPU / 65 GiB) | `Linux bench-c5513931990-2100-2xkzt 6.12.94+ #1 SMP Fri Jul 17 09:42:57 UTC 2026 aarch64 GNU/Linux`
   <details><summary>CPU Details (lscpu)</summary>
   
   ```
   Architecture:                            aarch64
   CPU op-mode(s):                          64-bit
   Byte Order:                              Little Endian
   CPU(s):                                  16
   On-line CPU(s) list:                     0-15
   Vendor ID:                               ARM
   Model name:                              Neoverse-V2
   Model:                                   1
   Thread(s) per core:                      1
   Core(s) per cluster:                     16
   Socket(s):                               -
   Cluster(s):                              1
   Stepping:                                r0p1
   BogoMIPS:                                2000.00
   Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
   L1d cache:                               1 MiB (16 instances)
   L1i cache:                               1 MiB (16 instances)
   L2 cache:                                32 MiB (16 instances)
   L3 cache:                                80 MiB (1 instance)
   NUMA node(s):                            1
   NUMA node0 CPU(s):                       0-15
   Vulnerability Gather data sampling:      Not affected
   Vulnerability Indirect target selection: Not affected
   Vulnerability Itlb multihit:             Not affected
   Vulnerability L1tf:                      Not affected
   Vulnerability Mds:                       Not affected
   Vulnerability Meltdown:                  Not affected
   Vulnerability Mmio stale data:           Not affected
   Vulnerability Reg file data sampling:    Not affected
   Vulnerability Retbleed:                  Not affected
   Vulnerability Spec rstack overflow:      Not affected
   Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
   Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
   Vulnerability Spectre v2:                Mitigation; CSV2, BHB
   Vulnerability Srbds:                     Not affected
   Vulnerability Tsa:                       Not affected
   Vulnerability Tsx async abort:           Not affected
   Vulnerability Vmscape:                   Not affected
   ```
   
   </details>
   
   Comparing ipc-decompression-size-upper-bound (eb92502eb182f5ecafa25fa03117f1bfa03e289f) to b84fc5c (merge-base) [diff](https://github.com/apache/arrow-rs/compare/b84fc5cfa9bbc8698d2487a444c6baaa489351f7..eb92502eb182f5ecafa25fa03117f1bfa03e289f)
   
   <details><summary>Run configuration</summary>
   
   ```yaml
   run benchmark ipc_reader
   ```
   
   </details>
   
   BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench ipc_reader
   Results will be posted here when complete
   
   ---
   [File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "adriangbot (via GitHub)" <gi...@apache.org>.
adriangbot commented on PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#issuecomment-5513538665

   Benchmark for [this request](https://github.com/apache/arrow-rs/pull/10959#issuecomment-5513518595) failed before finishing (Kubernetes reason: `BackoffLimitExceeded`).
   
   Benchmarks requested: `arrow-ipc`
   
   <details><summary>Kubernetes message</summary>
   
   ```
   Job has reached the specified backoff limit
   ```
   
   </details>
   
   ---
   [File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "Rich-T-kid (via GitHub)" <gi...@apache.org>.
Rich-T-kid commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r3916962754


##########
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:
   I'm not sure that we should make this public.
   
   do you have examples of when it would be useful to use this directly?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "azecevic000 (via GitHub)" <gi...@apache.org>.
azecevic000 commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r3924067141


##########
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:
   Thanks for pointing out to the issue, though the proposition is more about memory optimization if some kind of projection is done (which I agree can be significant for some workloads), the issue I raised is more concerned with having a guaranteed upper bound on memory allocation and knowing it before allocation happens.
   
   Thanks for the review, I totally understand general hesitation when expansion of the public API surface area is considered. In this case, though, I believe the decompressed size is more than internal detail, as downstream users can generally make decisions based on it.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r4043247707


##########
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:
   im a bit hesistant on making this public, especially given its a relatively simply function anyway. it just reads an i64 from a buffer, surely itd be easier to vendor that wherever its needed?



##########
arrow-ipc/src/compression.rs:
##########
@@ -375,21 +386,27 @@ 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> {
     let len_buffer = buffer.get(..LENGTH_OF_PREFIX_DATA as usize).ok_or_else(|| {
         ArrowError::IpcError(format!(
             "Compressed IPC buffer is too short: expected at least {LENGTH_OF_PREFIX_DATA} bytes, got {}",
             buffer.len()
         ))
     })?;
-    Ok(i64::from_le_bytes(len_buffer.try_into().unwrap()))
+    let len_buffer: [u8; 8] = len_buffer
+        .try_into()
+        .map_err(|e| ArrowError::IpcError(format!("Invalid uncompressed length prefix: {e}")))?;

Review Comment:
   is this error actually reachable? we already guarantee `len_buffer` has 8 bytes because of the `get()` above



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "azecevic000 (via GitHub)" <gi...@apache.org>.
azecevic000 commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r4070146727


##########
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:
   Reverted `pub` change, only LZ4 fix remains in this PR.
   
   > given its part of the IPC format specification, its more than a private implementation detail anyway
   
   Yeah, you're right, being part of the specification (with trivial implementation) makes this a non-issue, as even if a major version upgrade of the specification happens, it will surely have to provide backwards compatibility for quite some time.
   
   > what I would ideally want is an API that gives me an uncompressed size of the whole RecordBatch
   
   I guess the specification also makes this kind of computation stable and not reliant on implementation details (arguably this might change it https://github.com/apache/arrow-rs/issues/10392), though it's not trivial, so when I have some initial proposition (hopefully by the end of the week), I will share it, and we can discuss if you see the value in taking the ownership of that kind of API.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Expose IPC decompressed size and bound LZ4 output [arrow-rs]

Posted by "azecevic000 (via GitHub)" <gi...@apache.org>.
azecevic000 commented on code in PR #10959:
URL: https://github.com/apache/arrow-rs/pull/10959#discussion_r4066093436


##########
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:
   @Jefffrey Thanks for taking a look at this PR. It's not about the complexity of the function that would make this more convenient for downstream users. By staying private, any downstream user that would mimic this function would depend on a lot of implementation details that might change in the future (its first 8 bytes, its little-endian, etc.). So `pub` abstracts all of those details and leaves you just with `uncompressed_size: i64`.
   
   I explained my use-case in the comments above, and I dug deeper after those initial comments, and tbh I also wouldn't make this `pub` today, because it's still too low-level, it's just the uncompressed size of a single buffer, what I would ideally want is an API that gives me an uncompressed size of the whole `RecordBatch`.
   
   I will remove this `pub` change from this PR, and let's merge the LZ4 fix after that if you agree. I will open a feature request issue with a description of proposed changes, and I can open a separate PR with proposed changes. I'm very willing to work on this if we can agree on a general direction. I would like to get your feedback on that.
   
   @Rich-T-kid Thanks again for pointing https://github.com/apache/arrow-rs/issues/10392 to me. When I returned to it a few days after that comment, it actually made me think deeper about the problem at hand, and it's definitely related in some lower-level sense, and even clarified a few things for me.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org