Skip to content

Commit f2b489b

Browse files
committed
Fix LZ4 decompressor data leak when match offset is zero
When match offset is zero, the decompressor copies pre-existing data from the decompression buffer.
1 parent ff12c4d commit f2b489b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/main/java/io/airlift/compress/v3/lz4/Lz4RawDecompressor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static int decompress(
114114
input += SIZE_OF_SHORT;
115115

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

src/test/java/io/airlift/compress/v3/lz4/AbstractTestLz4.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ void testMatchLengthOverflow()
6363
byte[] data = buffer.toByteArray();
6464

6565
assertThatThrownBy(() -> getDecompressor().decompress(data, 0, data.length, new byte[2048], 0, 2048))
66-
.hasMessageMatching("Malformed input.*|Unknown error occurred.*");
66+
.hasMessageMatching("Malformed input.*|Unknown error occurred.*|offset outside destination buffer.*");
6767
}
6868
}

src/test/java/io/airlift/compress/v3/lz4/TestLz4.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515

1616
import io.airlift.compress.v3.Compressor;
1717
import io.airlift.compress.v3.Decompressor;
18+
import io.airlift.compress.v3.MalformedInputException;
1819
import io.airlift.compress.v3.thirdparty.JPountzLz4Compressor;
1920
import io.airlift.compress.v3.thirdparty.JPountzLz4Decompressor;
2021
import net.jpountz.lz4.LZ4Factory;
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2125

2226
class TestLz4
2327
extends AbstractTestLz4
@@ -45,4 +49,13 @@ protected Decompressor getVerifyDecompressor()
4549
{
4650
return new JPountzLz4Decompressor(LZ4Factory.fastestInstance());
4751
}
52+
53+
@Test
54+
void testZeroMatchOffset()
55+
{
56+
byte[] compressed = new byte[] {15, 0, 0, -1, -1, -118, 49, -1, -1, 0};
57+
assertThatThrownBy(() -> getDecompressor().decompress(compressed, 0, compressed.length, new byte[1024], 0, 1024))
58+
.isInstanceOf(MalformedInputException.class)
59+
.hasMessageContaining("offset outside destination buffer: offset=3");
60+
}
4861
}

0 commit comments

Comments
 (0)