From 5a16b827f665669162ffc8414fef2046c61da33a Mon Sep 17 00:00:00 2001 From: yawkat Date: Tue, 2 Dec 2025 11:44:47 +0100 Subject: [PATCH 1/3] fix src length in LZ4DecompressorTest --- src/test/net/jpountz/fuzz/LZ4DecompressorTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/net/jpountz/fuzz/LZ4DecompressorTest.java b/src/test/net/jpountz/fuzz/LZ4DecompressorTest.java index 163e34da..aad16178 100644 --- a/src/test/net/jpountz/fuzz/LZ4DecompressorTest.java +++ b/src/test/net/jpountz/fuzz/LZ4DecompressorTest.java @@ -31,14 +31,14 @@ private void test(FuzzedDataProvider data, LZ4Factory factory, boolean fast, boo if (fast) { factory.fastDecompressor().decompress(srcBuf, srcOff, destBuf, destOff, destLen); } else { - factory.safeDecompressor().decompress(srcBuf, srcOff, src.length - srcOffEnd, destBuf, destOff, destLen); + factory.safeDecompressor().decompress(srcBuf, srcOff, src.length - srcOffEnd - srcOff, destBuf, destOff, destLen); } } else { byte[] dest = new byte[destOff + destLen]; if (fast) { factory.fastDecompressor().decompress(src, srcOff, dest, destOff, destLen); } else { - factory.safeDecompressor().decompress(src, srcOff, src.length - srcOffEnd, dest, destOff); + factory.safeDecompressor().decompress(src, srcOff, src.length - srcOffEnd - srcOff, dest, destOff); } } } catch (LZ4Exception | ArrayIndexOutOfBoundsException ignored) { From 2c6df06406a239c7bcba6e34d50303f294f74110 Mon Sep 17 00:00:00 2001 From: yawkat Date: Tue, 2 Dec 2025 12:11:04 +0100 Subject: [PATCH 2/3] stop ignoring ArrayIndexOutOfBoundsException --- src/test/net/jpountz/fuzz/LZ4DecompressorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/net/jpountz/fuzz/LZ4DecompressorTest.java b/src/test/net/jpountz/fuzz/LZ4DecompressorTest.java index aad16178..d966983d 100644 --- a/src/test/net/jpountz/fuzz/LZ4DecompressorTest.java +++ b/src/test/net/jpountz/fuzz/LZ4DecompressorTest.java @@ -41,7 +41,7 @@ private void test(FuzzedDataProvider data, LZ4Factory factory, boolean fast, boo factory.safeDecompressor().decompress(src, srcOff, src.length - srcOffEnd - srcOff, dest, destOff); } } - } catch (LZ4Exception | ArrayIndexOutOfBoundsException ignored) { + } catch (LZ4Exception ignored) { } } From d8617c6acc9f05b3dda49e62cf59cbbc4fd67eaa Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Fri, 28 Nov 2025 00:22:02 +0100 Subject: [PATCH 3/3] Throw `LZ4Exception` on empty src for JNI fast decompressor This matches the recent changes for the non-JNI fast decompressors, and allows changing the fuzz test to not consider `ArrayIndexOutOfBoundsException` as expected exception anymore. --- .../net/jpountz/lz4/LZ4JNIFastDecompressor.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/java/net/jpountz/lz4/LZ4JNIFastDecompressor.java b/src/java/net/jpountz/lz4/LZ4JNIFastDecompressor.java index b669c533..0e7620a7 100644 --- a/src/java/net/jpountz/lz4/LZ4JNIFastDecompressor.java +++ b/src/java/net/jpountz/lz4/LZ4JNIFastDecompressor.java @@ -34,8 +34,14 @@ final class LZ4JNIFastDecompressor extends LZ4FastDecompressor { @Override public final int decompress(byte[] src, int srcOff, byte[] dest, int destOff, int destLen) { - SafeUtils.checkRange(src, srcOff); + int srcLen = src.length - srcOff; + SafeUtils.checkRange(src, srcOff, srcLen); SafeUtils.checkRange(dest, destOff, destLen); + + if (srcLen == 0) { + throw new LZ4Exception("Empty src"); + } + final int result = LZ4JNI.LZ4_decompress_fast(src, null, srcOff, dest, null, destOff, destLen); if (result < 0) { throw new LZ4Exception("Error decoding offset " + (srcOff - result) + " of input buffer"); @@ -46,9 +52,14 @@ public final int decompress(byte[] src, int srcOff, byte[] dest, int destOff, in @Override public int decompress(ByteBuffer src, int srcOff, ByteBuffer dest, int destOff, int destLen) { ByteBufferUtils.checkNotReadOnly(dest); - ByteBufferUtils.checkRange(src, srcOff); + int srcLen = src.capacity() - srcOff; + ByteBufferUtils.checkRange(src, srcOff, srcLen); ByteBufferUtils.checkRange(dest, destOff, destLen); + if (srcLen == 0) { + throw new LZ4Exception("Empty src"); + } + if ((src.hasArray() || src.isDirect()) && (dest.hasArray() || dest.isDirect())) { byte[] srcArr = null, destArr = null; ByteBuffer srcBuf = null, destBuf = null;