Skip to content

IPC LZ4 decompression allocates and zero-fills a fresh FrameDecoder per buffer #11129

Open

Description

@mzabaluev

Describe your question / problem

In arrow-ipc, decompress_lz4 constructs a new lz4_flex::frame::FrameDecoder for every buffer it decodes:

#[cfg(feature = "lz4")]
fn decompress_lz4(input: &[u8], decompressed_size: usize) -> Result<Vec<u8>, ArrowError> {
    use std::io::Read;
    let mut output = Vec::with_capacity(decompressed_size);
    lz4_flex::frame::FrameDecoder::new(input).read_to_end(&mut output)?;
    Ok(output)
}

A FrameDecoder starts with empty internal src/dst vectors and grows them on first use via

// lz4_flex 0.13.1, src/frame/decompress.rs:443
fn vec_resize_and_get_mut(v: &mut Vec<u8>, start: usize, end: usize) -> &mut [u8] {
    v.resize(end, 0)
    ...

Vec::resize zero-fills, and the buffer is then immediately overwritten in full by
read_exact.

Additional context

decompress() already threads a &mut DecompressionContext to both codec arms, and the zstd
arm uses it to hold a reusable decompressor:

let ret = match self {
    CompressionCodec::Lz4Frame => decompress_lz4(input, decompressed_size)?,          // context unused
    CompressionCodec::Zstd(_)  => decompress_zstd(input, decompressed_size, context)?, // context used
};

DecompressionContext's own doc comment states the intent:

... between subsequent decompression calls to avoid the performance overhead of initialising
a new context for every decompression.

and its only field today is #[cfg(feature = "zstd")] decompressor. So the mechanism to fix
this already exists and is already plumbed to the call site, but the LZ4 arm does
not use it.

Activity

  1. Rich-T-kid commented on Nov 6, 2026

    @Rich-T-kid
    Contributor

    closed by #12084

  2. mzabaluev commented on Nov 22, 2026

    @mzabaluev
    ContributorAuthor

    @Rich-T-kid #12084 deals with the encoder side, while this details a similar problem with the reader/decoder. Can this issue be reopened?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions