Skip to content

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

Open
Mola-maker/arrow-rs
#1

Description

@Tembocs

Describe the bug

arrow_ipc::reader::read_block (reader.rs:922) sizes its buffer from the
footer's Block before reading:

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 mut buf = MutableBuffer::from_len_zeroed(total_len);
reader.read_exact(&mut buf)?;

A 1,018-byte file whose footer holds a record-batch block with
bodyLength = 0x280000000240 (44 TB) reaches from_len_zeroed, which
ASan reports as allocation-size-too-big and which aborts the process on
a normal build. read_exact would have returned UnexpectedEof had the
allocation been bounded — the check exists one line too late.
FileReader::try_new verifies the footer's flatbuffer but not that its
blocks lie within the file.

To Reproduce

    cargo new ipc-repro && cd ipc-repro
    cargo add [email protected]
    # copy the attached block-body.arrow beside Cargo.toml

    // src/main.rs
    fn main() {
        let file = std::fs::File::open("block-body.arrow").unwrap();
        let reader = arrow_ipc::reader::FileReader::try_new(file, None).unwrap();
        for batch in reader {
            println!("{:?}", batch.map(|b| b.num_rows()));
        }
    }
cargo run --release

Expected behavior

Err(ArrowError::IpcError(..)) — the block is beyond the file.

Additional context

FileReader knows the file's length (it seeks to the footer). Checking
each block's offset + metaDataLength + bodyLength <= file_len when the
footer is parsed — or reading with a length-capped take into a growing
buffer in read_block — turns this into an error. The MessageReader
path (reader.rs:1845, from_len_zeroed(message.bodyLength())) has the
same shape for the stream format.

Linux x86_64, Rust stable 1.98.0. Found by fuzzing a reader built on the
crate.

Activity

  1. added theissue type on Aug 31, 2026
  2. added
    bug
    on Aug 31, 2026
  3. KHARSHAVARDHAN-eng commented on Aug 31, 2026

    @KHARSHAVARDHAN-eng

    @Tembocs , Thanks for the detailed report and the reproducible example. I’m interested in investigating this issue and working on a fix.

    From the description, it looks like the reader trusts the declared block/message body length before confirming that the data is actually available, which can lead to an excessively large allocation for malformed input. I’d like to investigate both the file IPC path and the stream/message reader path mentioned in the report, and add regression tests to ensure malformed length values return an appropriate ArrowError rather than causing an allocation failure or process abort.

    If no one is already working on this, would it be okay for me to take it up?

  4. Tembocs commented on Sep 5, 2026

    @Tembocs
    Author

    @Tembocs , Thanks for the detailed report and the reproducible example. I’m interested in investigating this issue and working on a fix.

    From the description, it looks like the reader trusts the declared block/message body length before confirming that the data is actually available, which can lead to an excessively large allocation for malformed input. I’d like to investigate both the file IPC path and the stream/message reader path mentioned in the report, and add regression tests to ensure malformed length values return an appropriate ArrowError rather than causing an allocation failure or process abort.

    If no one is already working on this, would it be okay for me to take it up?

    Yes, it is ok to take it. Please proceed.

  5. KHARSHAVARDHAN-eng commented on Sep 7, 2026

    @KHARSHAVARDHAN-eng

    @Tembocs Thanks for confirming! I’ve implemented the fix and added regression tests to ensure malformed block offsets/lengths are rejected before any oversized allocation occurs. I’ll open the PR shortly for review.

  6. geoHeil commented on Nov 15, 2026

    @geoHeil
    Contributor

    The same allocate-before-read pattern is also reachable through StreamReader: MessageReader::maybe_next resizes the metadata buffer from an untrusted length and then allocates message.bodyLength() before either read. A downstream fuzz run reached this after ~2.69M executions and OOMed, so the issue is not limited to read_block (run: https://github.com/telekom/sutura/actions/runs/43700135555/job/132769252432).

    I am preparing a patch covering all three sites without imposing a protocol-size limit:

    • read_block: reject checked body+metadata lengths that exceed the remaining file bytes before allocating.
    • MessageReader: validate signed lengths and read metadata/body incrementally in bounded chunks, growing the destination only as bytes actually arrive. Truncated declarations therefore return the read error with bounded memory instead of forcing the declared allocation; valid large messages remain supported.

    The patch will include truncated i32::MAX metadata and i64::MAX body regressions plus the existing valid-message suite. I will link it here when available.

  7. Mola-maker commented on Nov 22, 2026

    @Mola-maker
    Contributor

    Hi @geoHeil, I have a fix ready for the read_block part of this issue. It validates the block offset and lengths against the file length before allocating, and rejects blocks that extend past the end of the file. It follows the same approach as #11012, which was closed as abandoned.

    I saw your comment about preparing a patch covering all three sites, including the StreamReader path. Before I open a PR, I wanted to check: is your patch still coming, and would you prefer to cover read_block in it as well? Or is it fine for the read_block fix to land separately first, with the StreamReader part following in your patch?

  8. geoHeil commented on Nov 22, 2026

    @geoHeil
    Contributor

    well the patch is linked in my own project - vendored on nix. You can take that as reference potentially?

  9. geoHeil commented on Nov 22, 2026

    @geoHeil
    Contributor

    I originally intended to send it here only if one of the arrow-ipc core-team people really wants to get it - feel free to copy it from telekom/sutura#1930 and refine it

  10. Mola-maker commented on Nov 22, 2026

    @Mola-maker
    Contributor

    Thanks for u codebases
    emmm I'm not sure whether the core dev teams adapt this...
    I just act as core dev haha😄

  11. Mola-maker commented on Nov 22, 2026

    @Mola-maker
    Contributor

    @geoHeil Lucky to harvest a brandnew proj of codebases 👍

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions