Commit 626f5abb authored by Nick Terrell's avatar Nick Terrell Committed by Facebook Github Bot

Add fuzz testing

Summary: `ZSTD_decompress()` doesn't verify the uncompressed length in the frame as I thought, so throw an exception instead of `DCHECK()`.

Reviewed By: meyering

Differential Revision: D5234576

fbshipit-source-id: f72cf085a7267de32ce13553ce7ebbfe3b8a3f05
parent 26ca775e
......@@ -64,6 +64,9 @@ Codec::Codec(CodecType type) : type_(type) { }
// Ensure consistent behavior in the nullptr case
std::unique_ptr<IOBuf> Codec::compress(const IOBuf* data) {
if (data == nullptr) {
throw std::invalid_argument("Codec: data must not be nullptr");
}
uint64_t len = data->computeChainDataLength();
if (len == 0) {
return IOBuf::create(0);
......@@ -90,6 +93,9 @@ std::string Codec::compress(const StringPiece data) {
std::unique_ptr<IOBuf> Codec::uncompress(
const IOBuf* data,
Optional<uint64_t> uncompressedLength) {
if (data == nullptr) {
throw std::invalid_argument("Codec: data must not be nullptr");
}
if (!uncompressedLength) {
if (needsUncompressedLength()) {
throw std::invalid_argument("Codec: uncompressed length required");
......@@ -1787,7 +1793,9 @@ bool ZSTDStreamCodec::tryBlockUncompress(
size_t const length = ZSTD_decompress(
output.data(), *uncompressedLength(), input.data(), compressedLength);
zstdThrowIfError(length);
DCHECK_EQ(length, *uncompressedLength());
if (length != *uncompressedLength()) {
throw std::runtime_error("ZSTDStreamCodec: Incorrect uncompressed length");
}
input.uncheckedAdvance(compressedLength);
output.uncheckedAdvance(length);
return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment