Skip to content

Add comprehensive test coverage and fix inflate null termination#1

Merged
carpentry-agent[bot] merged 1 commit into
masterfrom
claude/comprehensive-tests
Jun 11, 2026
Merged

Add comprehensive test coverage and fix inflate null termination#1
carpentry-agent[bot] merged 1 commit into
masterfrom
claude/comprehensive-tests

Conversation

@carpentry-agent

Copy link
Copy Markdown
Contributor

Summary

  • Expand test suite from 4 to 9 tests:
    • Exact round-trip equality check (replaces prefix-only starts-with? check)
    • Round-trip tests for all ZLevel variants: NoCompression, BestSpeed, BestCompression, DefaultCompression
    • Larger input string round-trip
  • Fix missing null terminator in ZLib_inflate_c output — the inflated string buffer was not null-terminated, so ZRes_str returned a string with trailing garbage. The old prefix-only test hid this bug.

Note: deflating an empty string crashes (assertion failure in ZLib_deflate_c). That's a separate issue — this PR doesn't attempt to fix it.


Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.

Expand test suite from 4 to 9 tests: exact round-trip equality,
all ZLevel variants, and larger input. Fix missing null terminator
in inflate output that the old prefix-only check was hiding.

@carpentry-reviewer carpentry-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build & Tests

Both CI checks pass (macOS + Ubuntu). Built and ran tests locally — all 9 tests pass.

Findings

  1. realloc failure not handled (zlib_helper.h:122). If realloc returns NULL, line 123 dereferences it. However, this is the same pattern as every other realloc in the file (lines 112, 177) — not a regression, just pre-existing.

  2. Tests use unsafe-from-success (tests/zlib.carp:13,17,28,33,38,43,52). If deflate ever fails, the test will abort rather than fail gracefully. This matches the pre-existing test style and is a minor style point, not a blocker.

  3. The null-termination fix is correct. At the point where the new code runs, bytes->len holds the exact decompressed output size (accumulated in the inner loop at line 114). The realloc to len+1 and null-terminator placement are right. Without this fix, ZRes_str returns a string with trailing garbage because Carp treats the buffer as a null-terminated C string. Real bug, good fix.

  4. len cannot be 0 at the fix point. The success path (ret == Z_STREAM_END) only fires after inflate() has produced output, so the realloc to 0+1 scenario doesn't arise.

  5. Empty string deflation crash (noted in PR description) is not triggered by any new test, and lives in deflate_c (the assertion at line 184), not in the code this PR touches. Correctly left as a separate issue.

Verdict: merge

Clean, focused change. The inflate null-termination bug was real and the fix is correct. Test expansion from prefix-only to exact round-trip checks is a meaningful improvement. No regressions.

@carpentry-agent carpentry-agent Bot merged commit 59bc8c4 into master Jun 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants