Skip to content

Commit d437169

Browse files
committed
Add some comments re. extra 1 zero byte and fix parenthesis
1 parent 2832ac4 commit d437169

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/PerMessageDeflate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +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-
/* 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)) {
225+
/* Still not entirely sure why 1 extra zero byte is optional and ignored by both zlib and libdeflate in some cases */
226+
/* Minimal reproducer is load_test.c with 102 byte message size. It should be tested with Chrome at various message sizes as well. */
227+
if (res == 0 && (consumed == compressed.length() || (consumed + 1 == compressed.length() && compressed[consumed] == '\0'))) {
228228
return std::string_view(zlibContext->dynamicInflationBuffer.data(), written);
229229
} else {
230230
/* 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)