Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static int decompress(
input += SIZE_OF_SHORT;

long matchAddress = output - offset;
if (matchAddress < outputAddress) {
if (matchAddress < outputAddress || matchAddress >= output) {
throw new MalformedInputException(input - inputAddress, "offset outside destination buffer");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static int uncompressAll(
// bit 8).
int matchOffset = entry & 0x700;
matchOffset += trailer;
if (matchOffset < 0) {
if (matchOffset <= 0) {
throw new MalformedInputException(input - inputAddress);
}

Expand Down
12 changes: 11 additions & 1 deletion src/test/java/io/airlift/compress/lz4/TestLz4.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public void testMatchLengthOverflow()
byte[] data = buffer.toByteArray();

assertThatThrownBy(() -> new Lz4Decompressor().decompress(data, 0, data.length, new byte[2048], 0, 2048))
.isInstanceOf(MalformedInputException.class);
.isInstanceOf(MalformedInputException.class)
.hasMessageMatching("Malformed input.*|Unknown error occurred.*|offset outside destination buffer.*");
}

@Test
void testZeroMatchOffset()
{
byte[] compressed = new byte[] {15, 0, 0, -1, -1, -118, 49, -1, -1, 0};
assertThatThrownBy(() -> getDecompressor().decompress(compressed, 0, compressed.length, new byte[1024], 0, 1024))
.isInstanceOf(MalformedInputException.class)
.hasMessageContaining("offset outside destination buffer: offset=3");
}
}
9 changes: 9 additions & 0 deletions src/test/java/io/airlift/compress/snappy/TestSnappy.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@ public void testNegativeLength()
.isInstanceOf(MalformedInputException.class)
.hasMessageStartingWith("negative compressed length");
}

@Test
void testZeroMatchOffsetFails()
{
byte[] zeroMatchOffset = new byte[] {16, 1, 0, 1, 0, 1, 0, 1, 0};
assertThatThrownBy(() -> new SnappyDecompressor().decompress(zeroMatchOffset, 0, zeroMatchOffset.length, new byte[64], 0, 64))
.isInstanceOf(MalformedInputException.class)
.hasMessageContaining("Malformed input: offset=2");
}
}