Repository navigation
fix zlib throwing memory limit exceeded - #6294
Conversation
|
The change looks correct. Let me do a final review of all the pieces. Summary of my analysis:
The code is clean, correct, and well-tested. There are no actionable issues. LGTM |
zlib.inflateRawSync(data, { maxOutputLength: n }) threw "Memory limit
exceeded" for output of n bytes whenever n was above 40960, unless n
happened to land on the output buffer's growth steps: 50000-, 100000-
and 200000-byte entries all failed, while 81920 worked. adm-zip passes
an entry's exact size this way, so it fails on most entries over 40 KiB.
Any maxOutputLength that leaves less than 40 KiB of room after a full
buffer has the same problem, for every sync and callback zlib, brotli
and zstd function.
The sync loop asks its GrowableBuffer for another 40 KiB chunk each
time the codec fills the buffer, and the buffer refuses to grow past
maxOutputLength at all, rather than grow up to it. cloudflare#6294 fixed the case
where the whole output fits in the first chunk. The chunk the loop asks
for is now capped at maxOutputLength, so the codec gets whatever room is
left, and the existing check after a full buffer at maxOutputLength
decides whether the output fits.
maxOutputLengthAfterBufferGrowth and
zstdMaxOutputLengthAfterBufferGrowthTest decompress 40961 to 200000
bytes with maxOutputLength set to the output size and above it, and
check that one byte less still fails. They fail without this change.
Fixes #6286