Skip to content

Commit

Permalink
Fix bounds checks
Browse files Browse the repository at this point in the history
  • Loading branch information
martint committed Feb 11, 2024
1 parent 3c1c5e2 commit f95ac48
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,17 @@ public int decompress(
int decodedSize;
switch (blockType) {
case RAW_BLOCK:
verify(inputAddress + blockSize <= inputLimit, input, "Not enough input bytes");
verify(input + blockSize <= inputLimit, input, "Not enough input bytes");
decodedSize = decodeRawBlock(inputBase, input, blockSize, outputBase, output, outputLimit);
input += blockSize;
break;
case RLE_BLOCK:
verify(inputAddress + 1 <= inputLimit, input, "Not enough input bytes");
verify(input + 1 <= inputLimit, input, "Not enough input bytes");
decodedSize = decodeRleBlock(blockSize, inputBase, input, outputBase, output, outputLimit);
input += 1;
break;
case COMPRESSED_BLOCK:
verify(inputAddress + blockSize <= inputLimit, input, "Not enough input bytes");
verify(input + blockSize <= inputLimit, input, "Not enough input bytes");
decodedSize = decodeCompressedBlock(inputBase, input, blockSize, outputBase, output, outputLimit, frameHeader.windowSize, outputAddress);
input += blockSize;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/airlift/compress/zstd/TestZstd.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,6 @@ public void testBadHuffmanData()

assertThatThrownBy(() -> new ZstdDecompressor().decompress(data, 0, data.length, new byte[10], 0, 10))
.isInstanceOf(MalformedInputException.class)
.hasMessageStartingWith("Input is corrupted");
.hasMessageStartingWith("Not enough input bytes");
}
}

0 comments on commit f95ac48

Please sign in to comment.