Skip to content

Commit 2cea90a

Browse files
committed
Verify length is positive
1 parent 15e68df commit 2cea90a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/java/io/airlift/compress/snappy/SnappyRawDecompressor.java

+3
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ static int[] readUncompressedLength(Object compressed, long compressedAddress, l
306306
}
307307
}
308308
}
309+
if (result < 0) {
310+
throw new MalformedInputException(compressedAddress, "negative compressed length");
311+
}
309312
return new int[] {result, bytesRead};
310313
}
311314

src/test/java/io/airlift/compress/snappy/TestSnappy.java

+10
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,14 @@ public void testInvalidLiteralLength()
6767
assertThatThrownBy(() -> new SnappyDecompressor().decompress(data, 0, data.length, new byte[1024], 0, 1024))
6868
.isInstanceOf(MalformedInputException.class);
6969
}
70+
71+
@Test
72+
public void testNegativeLength()
73+
{
74+
byte[] data = {(byte) 255, (byte) 255, (byte) 255, (byte) 255, 0b0000_1000};
75+
76+
assertThatThrownBy(() -> SnappyDecompressor.getUncompressedLength(data, 0))
77+
.isInstanceOf(MalformedInputException.class)
78+
.hasMessageStartingWith("negative compressed length");
79+
}
7080
}

0 commit comments

Comments
 (0)