GHSA-343h-94h5-c4wr: Low severity maven/org.lz4:lz4-java vulnerability
Summary
When LZ4BlockInputStream is configured with stopOnEmptyBlock = false (the mode for reading concatenated block streams), it handles each empty block by calling refill() recursively. A long run of empty blocks exhausts the thread stack and throws StackOverflowError out of read() or skip().
Details
In net.jpountz.lz4.LZ4BlockInputStream.refill():
java if (originalLen == 0 && compressedLen == 0) { if (check != 0) { throw new IOException("Stream is corrupted"); } if (!stopOnEmptyBlock) { refill(); } else { finished = true; } return; }
Each well-formed empty block is 21 bytes and adds one stack frame, with no limit on nesting depth. In local testing, around 10,000 to 100,000 consecutive empty blocks (about 210 KB to 2.1 MB, depending on JIT state and thread stack size) threw StackOverflowError. StackOverflowError is an Error, not an IOException, so callers that only handle I/O errors for corrupt input don't catch it.
Impact
Applications that decode attacker-controlled LZ4Block streams with LZ4BlockInputStream.newBuilder().withStopOnEmptyBlock(false) or the deprecated LZ4BlockInputStream(InputStream, boolean) constructor can have the decoding thread fail with StackOverflowError. The default configuration (stopOnEmptyBlock = true) is not affected. There is no memory corruption. Availability impact only.
Patch
Fixed in lz4-java 1.11.4. Empty blocks are now skipped in a loop instead of by recursion, so any number of consecutive empty blocks uses constant stack space.
For older versions, the workaround is to use the default stopOnEmptyBlock = true for untrusted input, or catch StackOverflowError around the read loop.
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.4 - Upgrade
Upgrade
lz4-javato a version that resolves this vulnerability.Fixed in 1.11.4 - Configuration
For older versions and untrusted input, use the default stopOnEmptyBlock = true.
LZ4BlockInputStream stopOnEmptyBlock = true - Operational
For older versions, catch StackOverflowError around the read loop.
Event History
Frequently Asked Questions
Which applications are exposed to this issue?
Applications are exposed when they decode attacker-controlled LZ4Block streams using LZ4BlockInputStream with stopOnEmptyBlock set to false. This includes use of newBuilder().withStopOnEmptyBlock(false) and the deprecated LZ4BlockInputStream(InputStream, boolean) constructor in that mode.
What input is required to trigger the failure?
An attacker needs to supply a well-formed stream containing a long sequence of consecutive empty blocks. Each empty block is 21 bytes, and testing observed StackOverflowError after roughly 10,000 to 100,000 empty blocks, depending on JIT state and thread stack size.
Why may existing corrupt-input error handling not contain the impact?
The failure is a StackOverflowError thrown from read() or skip(), rather than an IOException. Code that only catches I/O exceptions for malformed or corrupt input will not catch this error.