GHSA-4v53-57pg-c464: Medium severity maven/org.lz4:lz4-java vulnerability
Summary
LZ4BlockInputStream grows its compressed-input buffer to the attacker-controlled compressedLen value from the legacy LZ4Block stream header before reading any payload bytes. A header-only input can therefore trigger a near-2 GiB allocation and exhaust the JVM heap.
Details
In net.jpountz.lz4.LZ4BlockInputStream, refill() validates that compressedLen is nonnegative but does not cap it before allocation:
java case COMPRESSIONMETHODLZ4: if (compressedBuffer.length < compressedLen) { compressedBuffer = new byte[Math.max(compressedLen, compressedBuffer.length 3 / 2)]; } readFully(compressedBuffer, compressedLen);
The paired LZ4BlockOutputStream never emits such a block. If compression is not smaller than the original block, it writes the block as RAW:
java if (compressedLength >= o) { compressMethod = COMPRESSIONMETHODRAW; compressedLength = o; } else { compressMethod = COMPRESSIONMETHODLZ4; }
Existing readers generally accept noncanonical LZ4-method blocks where compressedLen >= originalLen, but no canonical writer found produces them.
Impact
Applications that pass attacker-controlled legacy LZ4Block streams to LZ4BlockInputStream can suffer heap exhaustion from a header-only input. The impact is availability-only and requires no valid compressed payload.
Patch
As of lz4-java 1.11.2, lz4-java rejects lz4 blocks where the compressed length is larger than uncompressed. Readers would generally emit these as raw blocks instead. You can use the new acceptOversizedBlocks flag to restore the old behavior, but this reintroduces the DoS vector.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
maven/at.yawk.lz4:lz4-javato a version that resolves this vulnerability.Fixed in 1.11.2 - Upgrade
Upgrade
lz4-javato a version that resolves this vulnerability.Fixed in 1.11.2
Event History
Frequently Asked Questions
Which applications are exposed?
Applications are exposed if they pass attacker-controlled legacy LZ4Block streams to LZ4BlockInputStream. The issue is in the reader’s handling of the stream header before payload bytes are read.
What does an attacker need to provide to trigger the issue?
A header-only legacy LZ4Block input with an attacker-controlled, very large nonnegative compressedLen field can trigger allocation of a buffer approaching 2 GiB. No compressed payload bytes are required.
Can streams produced by the paired LZ4BlockOutputStream cause this condition?
The paired writer does not produce the problematic form: when compressed data is not smaller than the original block, it writes a RAW block instead. The affected reader nevertheless accepts noncanonical LZ4-method blocks with compressedLen greater than or equal to originalLen.
What is the practical impact of successful exploitation?
The allocation can exhaust the JVM heap, causing an availability impact. The provided severity vector indicates no confidentiality or integrity impact.