Partial stream headers misclassify ordinary input as compressed
perfloop-oss/compress · Value Kind Confusion
https://perfloop.ai/t/oss/case_vngj3re460
Verdict
VERIFIED · settled 2026-11-21 · merged as klauspost/compress#1341
What happened: The check fails before this change and passes with it.
Hypothesis
Ordinary file bytes can be mistaken for an already-compressed stream. The command then copies them into an executable without compression and can delete the original with -rm, even though the resulting archive cannot be decoded. A four-byte local counterexample is established. The prevalence of such input is unknown.
At revision 7213df05def493d5fb921e472b3f84d92db98aba, isS2Input tests only ff060000. That prefix is merely the type and length of a stream-identifier chunk. The authoritative identifiers also require the six-byte S2sTwO or sNaPpY body, defined in s2/s2.go:78–81 and checked by s2.Reader at s2/reader.go:363–375. main uses the ambiguous boolean at lines 126–130 and 160–220 to choose copying instead of compression. There is no filename or full-identifier guard before the -rm path. The required distinction here is ordinary input versus input bearing a complete supported identifier; this does not ask to validate an entire precompressed stream.
The new native file s2/cmd/_s2sx/perfloop_values_property_test.go checked byte preservation and classification with a 64-byte input cap, seeding every truncation of both ten-byte identifiers. `(cd s2/cmd/_s2sx && go test . -run '^$' -fuzz '^FuzzPerfloopInputKind$' -fuzztime=1s -parallel=1 -timeout=20s)` failed on seed 4 with `input=ff060000 compressed=true; complete stream identifier=false`. This was a seed counterexample, not a completed fuzz search.
TestPerfloopInputKindReplay used only those four bytes in input.bin, one -q -cpu=1 -rm child with a five-second deadline, and the actual generated archive body. `(cd s2/cmd/_s2sx && go test . -run '^TestPerfloop(MaxOverflow|InputKind)Replay$' -count=1 -v -timeout=30s)` failed with `raw input=ff060000: creation exit=0 sourceRetained=false decoded= decodeErr=s2: corrupt input; want original raw bytes`. The native stub was generated using the repository's existing build/compression steps. A replay seed was retained in the probe's testdata/fuzz directory, and scratch files were removed afterwards.
The Case proof target is lossless ordinary-input handling for truncated or mismatching identifiers through the command, with valid S2 and Snappy identifiers as copy-path controls. Preserve all probed bytes, file and stdin operation, and successful removal behavior. The checker layout is provisional. Confidence is medium; the local data-loss witness is established, but exposure is unmeasured.
Open PR https://github.com/klauspost/compress/pull/1297 owns output creation/finalization and leaves isS2Input and these branch decisions unchanged in its checked implementation at 6643fe3205b8d0fb3ae89c3338d2b6dc112e4f39. Contribution guidance names pull requests and no separate review archive. Local history is shallow and a bounded code-host history read returned HTTP 403, leaving recent merged history as a gap.
Change to test: Classify input as precompressed only after matching a complete supported S2 or Snappy stream identifier, replaying every probed byte. Otherwise compress it as ordinary data while preserving valid already-compressed wrapping, file/stdin support, and the successful-completion rule for source removal.
Where it lives
Evidence
The check fails before this change and passes with it: `s2sx losslessly compresses ordinary input with truncated or mismatching stream identifiers from files and stdin, copies valid S2 and Snappy streams unchanged, and removes file sources on successful -rm creation.`
Checks: 2 of 2 passed. Verification: no defect found.