Skip to content

Bugreport+Patch: CorruptedInputException when using UncompressedLZMA2OutputStream #21

@jiaz83

Description

@jiaz83

Hi,
I wanted to use LZMA2Options.MODE_UNCOMPRESSED mode and when reading back the data via XZInputStream, it always fails with CorruptedInputException. It always happens after 65536 written bytes.

Bug:
The issue is caused by an index bug for System.arraycopy in UncompressedLZMA2OutputStream / in write method:
System.arraycopy(buf, off, uncompBuf, uncompPos, copySize);
the start index of the copy is always fixed off(set) index and thus after writing LZMA2OutputStream.COMPRESSED_SIZE_MAX(65536) bytes, writeChunk is called but the copy again happens with same off(set) start index.

Simple Bugfix:
int offset=off; while (len > 0) { int copySize = Math.min(LZMA2OutputStream.COMPRESSED_SIZE_MAX - uncompPos, len); System.arraycopy(buf, offset, uncompBuf, uncompPos, copySize); offset+=copySize;
the offset for Sytem.arraycopy must move forward while we're copying data.

I've attached a simple test to reproduce the CorruptedInputException and pinpoint the 65536 index when corruption starts

CorruptedInputExceptionOnMODE_UNCOMPRESSED.java

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