-
-
Notifications
You must be signed in to change notification settings - Fork 25
Bugreport+Patch: CorruptedInputException when using UncompressedLZMA2OutputStream #21
Description
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