Never compress 0 bytes, finish pub/sub ded. compr.

This commit is contained in:
Alex Hultman
2020-06-22 07:10:43 +02:00
parent e9e6d3fa34
commit f52d816032
5 changed files with 21 additions and 10 deletions
+3 -1
View File
@@ -131,7 +131,7 @@ struct DeflationStream {
deflateInit2(&deflationStream, 1, Z_DEFLATED, windowBits, memLevel, Z_DEFAULT_STRATEGY);
}
/* Deflate and optionally reset */
/* Deflate and optionally reset. You must not deflate an empty string. */
std::string_view deflate(ZlibContext *zlibContext, std::string_view raw, bool reset) {
/* Odd place to clear this one, fix */
zlibContext->dynamicDeflationBuffer.clear();
@@ -167,6 +167,8 @@ struct DeflationStream {
return {(char *) zlibContext->dynamicDeflationBuffer.data(), zlibContext->dynamicDeflationBuffer.length() - 4};
}
/* Note: We will get an interger overflow resulting in heap buffer overflow if Z_BUF_ERROR is returned
* from passing 0 as avail_in. Therefore we must not deflate an empty string */
return {
zlibContext->deflationBuffer,
DEFLATE_OUTPUT_CHUNK - deflationStream.avail_out - 4