Skip to content

Commit

Permalink
Verify length is positive
Browse files Browse the repository at this point in the history
  • Loading branch information
martint committed Feb 13, 2024
1 parent 15e68df commit 2cea90a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ static int[] readUncompressedLength(Object compressed, long compressedAddress, l
}
}
}
if (result < 0) {
throw new MalformedInputException(compressedAddress, "negative compressed length");
}
return new int[] {result, bytesRead};
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/java/io/airlift/compress/snappy/TestSnappy.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,14 @@ public void testInvalidLiteralLength()
assertThatThrownBy(() -> new SnappyDecompressor().decompress(data, 0, data.length, new byte[1024], 0, 1024))
.isInstanceOf(MalformedInputException.class);
}

@Test
public void testNegativeLength()
{
byte[] data = {(byte) 255, (byte) 255, (byte) 255, (byte) 255, 0b0000_1000};

assertThatThrownBy(() -> SnappyDecompressor.getUncompressedLength(data, 0))
.isInstanceOf(MalformedInputException.class)
.hasMessageStartingWith("negative compressed length");
}
}

0 comments on commit 2cea90a

Please sign in to comment.