Skip to content

Commit 2832ac4

Browse files
committed
Allow a zero byte padding after deflate input
1 parent c445faa commit 2832ac4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/PerMessageDeflate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ struct InflationStream {
222222
((char *)compressed.data())[0] |= 0x1; // BFINAL = 1
223223
libdeflate_result res = libdeflate_deflate_decompress_ex(zlibContext->decompressor, compressed.data(), compressed.length(), zlibContext->dynamicInflationBuffer.data(), maxPayloadLength, &consumed, &written);
224224

225-
if (res == 0 && consumed == compressed.length()) {
225+
/* DEFLATE is not a byte aligned format, so we might end up consuming 1 byte less than the input */
226+
/* This extra byte is zero-padding. */
227+
if (res == 0 && consumed == compressed.length() || (consumed == compressed.length() - 1 && compressed.data()[consumed] == 0)) {
226228
return std::string_view(zlibContext->dynamicInflationBuffer.data(), written);
227229
} else {
228230
/* We can only end up here if the first DEFLATE block was not the last, so mark it as such */

0 commit comments

Comments
 (0)