if (output.empty()) {
buffer->prependChain(addOutputBuffer(output, kDefaultBufferLength));
}
+ size_t const inputSize = input.size();
+ size_t const outputSize = output.size();
bool const done = compressStream(input, output, flushOp);
if (done) {
DCHECK(input.empty());
DCHECK_EQ(current->next(), data);
break;
}
+ if (inputSize == input.size() && outputSize == output.size()) {
+ throw std::runtime_error("Codec: No forward progress made");
+ }
}
buffer->prev()->trimEnd(output.size());
return buffer;
if (output.empty()) {
buffer->prependChain(addOutputBuffer(output, defaultBufferLength));
}
+ size_t const inputSize = input.size();
+ size_t const outputSize = output.size();
bool const done = uncompressStream(input, output, flushOp);
if (done) {
break;
}
+ if (inputSize == input.size() && outputSize == output.size()) {
+ throw std::runtime_error("Codec: Truncated data");
+ }
}
if (!input.empty()) {
throw std::runtime_error("Codec: Junk after end of data");
if (stream.avail_out == 0) {
out->prependChain(addOutputBuffer(&stream, kDefaultBufferLength));
}
-
+ size_t const outputSize = stream.avail_out;
rc = bzCheck(BZ2_bzDecompress(&stream));
+ if (outputSize == stream.avail_out) {
+ throw std::runtime_error("Bzip2Codec: Truncated input");
+ }
}
out->prev()->trimEnd(stream.avail_out);
EXPECT_THROW(codec_->uncompress(compressed.get(), uncompressedLength + 1),
std::runtime_error);
+ auto corrupted = compressed->clone();
+ corrupted->unshare();
+ // Truncate the last character
+ corrupted->prev()->trimEnd(1);
+ if (!codec_->needsUncompressedLength()) {
+ EXPECT_THROW(codec_->uncompress(corrupted.get()),
+ std::runtime_error);
+ }
+
+ EXPECT_THROW(codec_->uncompress(corrupted.get(), uncompressedLength),
+ std::runtime_error);
+
+ corrupted = compressed->clone();
+ corrupted->unshare();
// Corrupt the first character
- ++(compressed->writableData()[0]);
+ ++(corrupted->writableData()[0]);
if (!codec_->needsUncompressedLength()) {
- EXPECT_THROW(codec_->uncompress(compressed.get()),
+ EXPECT_THROW(codec_->uncompress(corrupted.get()),
std::runtime_error);
}
- EXPECT_THROW(codec_->uncompress(compressed.get(), uncompressedLength),
+ EXPECT_THROW(codec_->uncompress(corrupted.get(), uncompressedLength),
std::runtime_error);
}