You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LZ4DecompressorWithLength safe paths accept output shorter than the declared length #105
If the 4-byte length prefix says N, but the data decompresses to M < N bytes, the safe overloads of LZ4DecompressorWithLength don't reject it:
decompress(byte[] src, int srcOff, int srcLen) (line 301) silently returns a truncated M-byte array. LZ4SafeDecompressor.decompress(.., maxDestLen) trims it with Arrays.copyOf.
The non-allocating byte[]/ByteBuffer overloads (lines 241, 375) return written = M. A caller that trusts getDecompressedLength(src) instead of the return value reads dest[destOff+M .. destOff+N), which is whatever was in its own buffer before, for example a pooled buffer.
decompress(ByteBuffer, ByteBuffer) (line 321) advances dest by M and silently accepts the short output.
The fast paths already require exactly destLen bytes.
Fix: in the safe paths, throw LZ4Exception when written != destLen, so they behave like the fast paths.
privatestaticintcheckWritten(intwritten, intdeclared) {
if (written != declared) thrownewLZ4Exception(
"Decompressed " + written + " bytes, but length prefix declared " + declared);
returnwritten;
}
In the ByteBuffer, ByteBuffer overload, check before updating the positions. Update the @return Javadoc wording to match.
Add a test that compresses 16 bytes, rewrites the prefix to 20, and asserts that every safe overload throws.
Activity
Reject short output in LZ4DecompressorWithLength safe paths
Reject short output in LZ4DecompressorWithLength safe paths (#126)