Preserve actual byte counts on late checksum failures

perfloop-oss/lz4-c · Uncatalogued correctness

https://perfloop.ai/t/oss/case_w9hjgnfshg

Verdict

VERIFIED · settled 2026-11-04

What happened: The check fails before this change and passes with it.

Hypothesis

A checksum failure can occur after the decoder has already consumed input and written output. The public postcondition promises actual byte counts, but these error returns leave both counters at zero. This is a reproducible disagreement between writes and reported counts, not a claim that output from a failed frame should be trusted.

LZ4F_decompress zeroes both size pointers at entry. It publishes the accumulated cursor differences only at lines 3553-3554. The content-checksum error at line 3492, and other late error exits, return before that publication. lib/lz4frame.h:543-545 and 573-575 do not qualify the actual-count postcondition for errors. The separate reset-after-error rule at 570-571 still applies; no resumability after an error is requested.

The native errorByteCounts check on property prop_e3m76gr301 failed at revision ebf8859ddb62cfe1ce2eb1eee4f5bee94a5f21b1. A valid frame encoding one zero byte was changed only in its final content-checksum byte. With a one-byte destination, the decoder wrote the original byte and returned ERROR_contentChecksum_invalid, but reported_output=0 and reported_input=0 for the 20 supplied bytes. The stored replay tuple is 1 0 0 0. A second checkProperty run reproduced the failure without searching and exited 1 on 0 != 1. The retained command compiles tests/unit/unittest_perfloop_errorcounts.c with the repository unit runner and runs errorByteCounts -s1. The planned bounded enumeration covers binary payloads of lengths 1..3, block checksums on/off and two sufficient output capacities; the failing run stopped at the first tuple.

The refreshed open-PR page contains https://github.com/lz4/lz4/pull/2044 and https://github.com/lz4/lz4/pull/2045. Their actual patches concern CLI listing bounds and file timestamps, not decoder count publication. Merged https://github.com/lz4/lz4/pull/1854 adds file seeking and returns immediately on a decoder error; it does not repair this postcondition. No known consumer dependence on counts after errors has been established.

The first useful Case check is the retained checksum-only witness, followed by a comparison of successful and late-error paths after count publication is made consistent. It must distinguish bytes produced from bytes whose integrity has been validated and preserve the reset requirement. The particular checker layout is provisional; the requested outcome is truthful byte-count reporting, not continued decoding from a failed context.

Change to test: Publish the actual consumed and produced counts when a late checksum failure returns, without making the context resumable. Document the distinction between produced bytes and checksum-validated data so a nonzero count does not imply integrity.

Where it lives

perfloop-oss/lz4-c

Evidence

The check fails before this change and passes with it: `For frames corrupted only in a checksum, LZ4F_decompress reports input consumed through the failing checksum and output produced before that failure on the current call, returns the checksum error, and decodes a valid frame after reset: binary payloads of lengths 1..3 with block checksums on/off and two sufficient output capacities, and compressed/raw multi-block frames with whole or split input and direct or buffered output.`

Checks: 3 of 3 passed. Verification: no defect found.

Timeline