Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Data larger than 4194304 Bytes is not decompressed correctly  #203

Open

Description

@mgrundie-r7
    Random random = new Random();
    data = new byte[4194304];
    random.nextBytes(data);

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    LZ4FrameOutputStream lz4FrameOutputStream = new LZ4FrameOutputStream(byteArrayOutputStream);
    lz4FrameOutputStream.write(data);
    lz4FrameOutputStream.close();

    byte[] compressedBytes = byteArrayOutputStream.toByteArray();
    LZ4FrameInputStream compressedInputStream = new LZ4FrameInputStream(new ByteArrayInputStream(compressedBytes));

    byte[] decompressedData = new byte[data.length];
    compressedInputStream.read(decompressedData);
    compressedInputStream.close();

    assertTrue(Arrays.equals(data, decompressedData));

The above assertion passes. If you update the code to data = new byte[4194305]; then the assertion fails and the 4194305th element of decompressedData (decompressedData[4194304]) will equal 0

Activity

  1. petoncle commented on Feb 13, 2023

    @petoncle

    That's because you are decompressing only one block (you should call compressedInputStream .read() more than once).
    Instead of:

    byte[] decompressedData = new byte[data.length];
    compressedInputStream.read(decompressedData);

    Try:

    byte[] decompressedData = compressedInputStream.readAllBytes();
  2. mgrundie-r7 commented on Feb 14, 2023

    @mgrundie-r7
    Author

    I can't control what the callers do and the callers have no specific knowledge which type of InputStream this is. I ended up writing an adapter that extends InputStream and delegates to LZ4FrameInputStream to add some reset capability and to chunk read when read is asked to read > 4194304

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