Repository navigation
[#1752] Fix infinite loop in pgmoneta_gunzip_string on truncated input - #1753
Conversation
|
Hi @jesperpedersen, @Pranav-error, This PR addresses an issue where Since Key updates:
Could you please review when you have a moment? Thanks! |
|
CI fails on the new test itself in all 6 clang Debug jobs: it expects Locally with ASan it passes as |
…ted input
When decompressing gzip strings, pgmoneta_gunzip_string() loops on
inflate() with:
while (ret == Z_OK || ret == Z_BUF_ERROR);
When provided with an empty buffer, truncated stream, or corrupt payload
where stream.avail_in reaches 0 before Z_STREAM_END, inflate() returns
Z_BUF_ERROR. Because stream.avail_out > 0 and no more input can be
provided, the function spins in an infinite loop consuming 100% CPU.
Fix this by only retrying on Z_BUF_ERROR when stream.avail_out == 0
(indicating more output buffer capacity is needed). Also add parameter
validation in pgmoneta_gunzip_string() and pgmoneta_gzip_string(), and
add unit tests covering empty, truncated, and round-trip decompression.
Fixes pgmoneta#1752
Signed-off-by: Hardik Kaurani <[email protected]>
0820671 to
1c1a843
Compare
|
@Pranav-error Thanks for catching that! Updated |
|
Thanks @ecleon26 |
Closes #1752
Summary
pgmoneta_gunzip_string()(src/libpgmoneta/gzip_compression.c) when processing empty buffers, truncated gzip streams, or corrupt payloads.while (ret == Z_OK || ret == Z_BUF_ERROR);continued without checkingstream.avail_out == 0. Whenstream.avail_in == 0beforeZ_STREAM_END, in-memory decompression cannot make further progress, causinginflate()to continuously returnZ_BUF_ERRORand spin forever at 100% CPU.while (ret == Z_OK || (ret == Z_BUF_ERROR && stream.avail_out == 0));soZ_BUF_ERRORis only retried when the output buffer was completely exhausted and needs enlargement.pgmoneta_gunzip_string()(checking NULL pointers,compressed_size == 0, andcompressed_size > UINT_MAX) andpgmoneta_gzip_string().test_compression_gunzip_string_truncated_and_emptyintest/testcases/test_compression.cvalidating NULL handling, 0-byte input, truncated gzip headers, truncated gzip streams, and full round-trip compression and decompression.Verification
src/libpgmoneta/gzip_compression.candtest/testcases/test_compression.cwithclang-format.clang-format --dry-run --Werror.