Skip to content

fix(ipc): validate block lengths before allocation - #11012

Closed
KHARSHAVARDHAN-eng wants to merge 1 commit into
apache:mainfrom
KHARSHAVARDHAN-eng:fix-ipc-block-length-allocation
Closed

KHARSHAVARDHAN-eng wants to merge 1 commit into
apache:mainfrom
KHARSHAVARDHAN-eng:fix-ipc-block-length-allocation

Conversation

@KHARSHAVARDHAN-eng

Copy link
Copy Markdown

Closes #10921

Summary

  • Validate IPC footer block offsets and lengths against the file size before allocating the block buffer.
  • Use checked integer conversions and arithmetic for block offsets and lengths.
  • Add a regression test covering oversized, negative, out-of-bounds, and overflowing block metadata.

Validation

  • cargo fmt --check
  • cargo clippy -p arrow-ipc --all-targets -- -D warnings
  • cargo test -p arrow-ipc
  • git diff --check

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-ipc arrow-ipc crate labels Sep 7, 2026
Comment thread arrow-ipc/src/reader.rs
let body_len = block.bodyLength().to_usize().unwrap();
let metadata_len = block.metaDataLength().to_usize().unwrap();
let total_len = body_len.checked_add(metadata_len).unwrap();
let offset = u64::try_from(block.offset())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be worth placing all the parsing Errors into a anon function that takes in a string. either way otherwise this makes sense 👍

@apache apache deleted a comment Sep 8, 2026
Comment thread arrow-ipc/src/reader.rs Outdated
ArrowError::ParseError("Block body length + metadata length overflowed usize".to_string())
})?;

let file_len = reader.seek(SeekFrom::End(0))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should pass in the file length to the function, instead of re-seeking for every block read

@KHARSHAVARDHAN-eng
KHARSHAVARDHAN-eng force-pushed the fix-ipc-block-length-allocation branch from b94fc60 to a4921f1 Compare September 9, 2026 07:43
@KHARSHAVARDHAN-eng

Copy link
Copy Markdown
Author

Thanks for the review! I’ve addressed Jeffrey’s suggestion by calculating the file length once and passing it through to read_block, avoiding repeated end-of-file seeks. The changes have been verified with formatting, clippy, and the full arrow-ipc test suite. Ready for review.

@Jefffrey

Copy link
Copy Markdown
Contributor

run benchmark ipc_reader

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c5707577512-2399-42cr9 6.12.94+ #1 SMP Tue Aug 4 08:44:15 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
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

Comparing fix-ipc-block-length-allocation (a4921f1) to b06b9c1 (merge-base) diff

Run configuration
run benchmark ipc_reader

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 against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Arrow criterion benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

Comparing fix-ipc-block-length-allocation (a4921f1) to b06b9c1 (merge-base) diff

Run configuration
run benchmark ipc_reader
CPU Details (lscpu)
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

group                                                       fix-ipc-block-length-allocation        main
-----                                                       -------------------------------        ----
arrow_ipc_reader/FileReader/no_validation/read_10           1.00   122.0±12.52µs        ? ?/sec    1.07   130.7±16.88µs        ? ?/sec
arrow_ipc_reader/FileReader/no_validation/read_10/mmap      1.00     58.2±0.92µs        ? ?/sec    1.01     58.6±0.89µs        ? ?/sec
arrow_ipc_reader/FileReader/read_10                         1.00   414.0±45.48µs        ? ?/sec    1.07   442.6±60.75µs        ? ?/sec
arrow_ipc_reader/FileReader/read_10/mmap                    1.01   491.9±35.86µs        ? ?/sec    1.00   486.2±38.95µs        ? ?/sec
arrow_ipc_reader/StreamReader/no_validation/read_10         1.00    115.7±7.91µs        ? ?/sec    1.03   119.5±10.42µ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.02   419.0±29.99µs        ? ?/sec    1.00   409.7±41.04µs        ? ?/sec
arrow_ipc_reader/StreamReader/read_10/zstd                  1.01      2.8±0.02ms        ? ?/sec    1.00      2.7±0.01ms        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 85.0s
Peak memory 15.9 MiB
Avg memory 11.7 MiB
CPU user 71.4s
CPU sys 9.4s
Peak spill 0 B

branch

Metric Value
Wall time 85.0s
Peak memory 15.1 MiB
Avg memory 11.0 MiB
CPU user 69.3s
CPU sys 9.7s
Peak spill 0 B

File an issue against this benchmark runner

Comment thread arrow-ipc/src/reader.rs
Comment on lines +4344 to +4351
let mut reader = match FileReaderBuilder::new().build(std::io::Cursor::new(file)) {
Ok(reader) => reader,
Err(err) => {
assert!(
matches!(err, ArrowError::ParseError(_)),
"expected ParseError for block ({body_length}, {meta_length}, {offset}): {err}"
);
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldnt have this approach in tests; it makes it unclear which test case here is expected to pass or fail this specific assertion. can we split the cases up to be clear which should successfully build a reader and which should fail

@Rich-T-kid Rich-T-kid added the bug Squash those bugs label Oct 22, 2026
@alamb

alamb commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

This PR looks abandoned and I don't see any evidence of human engagement. I am going to close it for now; Please reopen and respond to reviewer comments if you want to proceed with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-ipc arrow-ipc crate bug Squash those bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

arrow-ipc: a footer block's declared body length is zero-filled before it is read

5 participants