Repository navigation
[#1758] Fix buffer expansion and strict aliasing in pgmoneta_bunzip2_string - #1759
hardikkaurani wants to merge 1 commit into
Conversation
|
Hi @jesperpedersen and @Pranav-error, I have opened this PR to address #1758 in
Formatted with |
|
Same CI failure as #1753: |
2746a1f to
e9f210c
Compare
|
@Pranav-error Good catch — updated |
| /* High compression ratio requiring buffer expansion (ratio > 20x) */ | ||
| large_string = malloc(large_len + 1); | ||
| MCTF_ASSERT_PTR_NONNULL(large_string, cleanup, "allocation for large test string failed"); | ||
| while (pos + pattern_len <= large_len) | ||
| { | ||
| memcpy(large_string + pos, pattern, pattern_len); | ||
| pos += pattern_len; | ||
| } | ||
| large_string[pos] = '\0'; | ||
|
|
||
| MCTF_ASSERT_INT_EQ(pgmoneta_bzip2_string(large_string, &bz, &bz_size), 0, cleanup, "bzip2 compression of large payload failed"); | ||
| MCTF_ASSERT_PTR_NONNULL(bz, cleanup, "compressed buffer is NULL"); |
There was a problem hiding this comment.
Split this
the round trip and expansion should be a MCTF_TEST, and only the invalid stream / NULL cases in MCTF_TEST_NEGATIVE
There was a problem hiding this comment.
@ecleon26 Split into MCTF_TEST(test_compression_bzip2_string_roundtrip_and_expansion) and MCTF_TEST_NEGATIVE(test_compression_bzip2_string_invalid_and_null) in 391afddd.
e9f210c to
391afdd
Compare
|
@ecleon26 Split |
|
@hardikkaurani Please rebase |
391afdd to
3b10211
Compare
|
@ecleon26 Rebased onto |
…bunzip2_string Signed-off-by: Hardik Kaurani <[email protected]>
Closes #1758
Summary
src/libpgmoneta/bzip2_compression.c, handleBZ_OUTBUFF_FULLinpgmoneta_bunzip2_string()by dynamically expanding the buffer capacity and retrying, allowing high-ratio compressed payloads to decompress successfully.dest_lenas a properly typedunsigned int*toBZ2_bzBuffToBuffDecompress()to comply with strict aliasing and prevent partial 4-byte writes into a 64-bitsize_tvariable.pgmoneta_bzip2_string()andpgmoneta_bunzip2_string(), and ensure explicit null-termination of the decompressed output string.test/testcases/test_compression.c(test_compression_bzip2_string_bounds_and_expansion) covering parameter validation, normal round-trip decompression, buffer expansion on a stream with a > 20:1 compression ratio, and corrupted streams.Verification
src/libpgmoneta/bzip2_compression.candtest/testcases/test_compression.cwithclang-format(clang-format --dry-run --Werrorpassed).git diff --checkwith 0 whitespace warnings.upstream/mainas a single signed-off commit.