CVE-2024-36114: Insufficient Information (NVD-CWE-noinfo)
value: Aircompressor is a library with ports of the Snappy, LZO, LZ4, and Zstandard compression algorithms to Java. All decompressor implementations of Aircompressor (LZ4, LZO, Snappy, Zstandard) can crash the JVM for certain input, and in some cases also leak the content of other memory of the Java process (which could contain sensitive information). When decompressing certain data, the decompressors try to access memory outside the bounds of the given byte arrays or byte buffers. Because Aircompressor uses the JDK class `sun.misc.Unsafe` to speed up memory access, no additional bounds checks are performed and this has similar security consequences as out-of-bounds access in C or C++, namely it can lead to non-deterministic behavior or crash the JVM. Users should update to Aircompressor 0.27 or newer where these issues have been fixed. When decompressing data from untrusted users, this can be exploited for a denial-of-service attack by crashing the JVM, or to leak other sensitive information from the Java process. There are no known workarounds for this issue.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
Published: 2024-05-29T21:15Z
Repository: https://github.com/airlift/aircompressor
Language: Java
Files changed: src/main/java/io/airlift/compress/lz4/Lz4RawDecompressor.java, src/main/java/io/airlift/compress/lzo/LzoRawDecompressor.java, src/main/java/io/airlift/compress/zstd/ZstdFrameDecompressor.java
Commit date: 2024-02-13 08:10:53 -0800
Commit message: Add missing bounds checks

Diff: diff --git a/src/main/java/io/airlift/compress/lz4/Lz4RawDecompressor.java b/src/main/java/io/airlift/compress/lz4/Lz4RawDecompressor.java
index 7993ad3..785e478 100644
--- a/src/main/java/io/airlift/compress/lz4/Lz4RawDecompressor.java
+++ b/src/main/java/io/airlift/compress/lz4/Lz4RawDecompressor.java
@@ -60,10 +60,13 @@ public final class Lz4RawDecompressor
             final int token = UNSAFE.getByte(inputBase, input++) & 0xFF;
 
             // decode literal length
             int literalLength = token >>> 4; // top-most 4 bits of token
             if (literalLength == 0xF) {
+                if (input >= inputLimit) {
+                    throw new MalformedInputException(input - inputAddress);
+                }
                 int value;
                 do {
                     value = UNSAFE.getByte(inputBase, input++) & 0xFF;
                     literalLength += value;
                 }
diff --git a/src/main/java/io/airlift/compress/lzo/LzoRawDecompressor.java b/src/main/java/io/airlift/compress/lzo/LzoRawDecompressor.java
index 2a8dcc4..9803d2b 100644
--- a/src/main/java/io/airlift/compress/lzo/LzoRawDecompressor.java
+++ b/src/main/java/io/airlift/compress/lzo/LzoRawDecompressor.java
@@ -323,11 +323,11 @@ public final class LzoRawDecompressor
                 if (literalLength < 0) {
                     throw new MalformedInputException(input - inputAddress);
                 }
                 long literalOutputLimit = output + literalLength;
                 if (literalOutputLimit > fastOutputLimit || input + literalLength > inputLimit - SIZE_OF_LONG) {
-                    if (literalOutputLimit > outputLimit) {
+                    if (literalOutputLimit > outputLimit || input + literalLength > inputLimit) {
                         throw new MalformedInputException(input - inputAddress);
                     }
 
                     // slow, precise copy
                     UNSAFE.copyMemory(inputBase, input, outputBase, output, literalLength);
diff --git a/src/main/java/io/airlift/compress/zstd/ZstdFrameDecompressor.java b/src/main/java/io/airlift/compress/zstd/ZstdFrameDecompressor.java
index 03754c3..617469f 100644
--- a/src/main/java/io/airlift/compress/zstd/ZstdFrameDecompressor.java
+++ b/src/main/java/io/airlift/compress/zstd/ZstdFrameDecompressor.java
@@ -195,10 +195,11 @@ class ZstdFrameDecompressor
             if (frameHeader.hasChecksum) {
                 int decodedFrameSize = (int) (output - outputStart);
 
                 long hash = XxHash64.hash(0, outputBase, outputStart, decodedFrameSize);
 
+                verify(input + SIZE_OF_INT <= inputLimit, input, "Not enough input bytes");
                 int checksum = UNSAFE.getInt(inputBase, input);
                 if (checksum != (int) hash) {
                     throw new MalformedInputException(input, format("Bad checksum. Expected: %s, actual: %s", Integer.toHexString(checksum), Integer.toHexString((int) hash)));
                 }
 
@@ -508,18 +509,19 @@ class ZstdFrameDecompressor
                 literalsInput = literalEnd;
             }
         }
 
         // last literal segment
-        output = copyLastLiteral(outputBase, literalsBase, literalsLimit, output, literalsInput);
+        output = copyLastLiteral(input, literalsBase, literalsInput, literalsLimit, outputBase, output, outputLimit);
 
         return (int) (output - outputAddress);
     }
 
-    private static long copyLastLiteral(Object outputBase, Object literalsBase, long literalsLimit, long output, long literalsInput)
+    private static long copyLastLiteral(long input, Object literalsBase, long literalsInput, long literalsLimit, Object outputBase, long output, long outputLimit)
     {
         long lastLiteralsSize = literalsLimit - literalsInput;
+        verify(output + lastLiteralsSize <= outputLimit, input, "Output buffer too small");
         UNSAFE.copyMemory(literalsBase, literalsInput, outputBase, output, lastLiteralsSize);
         output += lastLiteralsSize;
         return output;
     }
 

Vulnerable code:                     if (literalOutputLimit > outputLimit) {
        output = copyLastLiteral(outputBase, literalsBase, literalsLimit, output, literalsInput);
    private static long copyLastLiteral(Object outputBase, Object literalsBase, long literalsLimit, long output, long literalsInput)
Fixed code:                 if (input >= inputLimit) {
                    throw new MalformedInputException(input - inputAddress);
                }
                    if (literalOutputLimit > outputLimit || input + literalLength > inputLimit) {
                verify(input + SIZE_OF_INT <= inputLimit, input, "Not enough input bytes");
        output = copyLastLiteral(input, literalsBase, literalsInput, literalsLimit, outputBase, output, outputLimit);
    private static long copyLastLiteral(long input, Object literalsBase, long literalsInput, long literalsLimit, Object outputBase, long output, long outputLimit)
        verify(output + lastLiteralsSize <= outputLimit, input, "Output buffer too small");