# TAR boundaries after successful gzip validation

A controlled observation on GNU tar 1.35, GNU gzip 1.12 and CPython 3.12.3.
Eight synthetic fixtures, six TAR reader operations each. This is a reproduction
and comparison of documented parser behavior, not a newly discovered defect,
failure-rate study, security audit or hardware test.

## Reproduce
Requirements: Python 3.10+, GNU tar and GNU gzip on PATH. No packages installed.
No existing archive is accepted. The runner constructs at most a few KiB per
fixture in memory and uses bounded subprocesses; it extracts only to stdout or
Python memory. It does not restore file metadata or create extracted files.

    python3 -B observe.py --output fresh-results.json
    python3 -B -m unittest -v test_observe.py
    python3 -O -B -m unittest -v test_observe.py

Tests compare this recorded build's outcomes; a different implementation can
legitimately fail a version-specific expectation. Preserve a new receipt rather
than overwriting results.json. The replay comparison includes gzip byte hashes:
different gzip implementations may change compressed representation.

## Method
Expected alpha.bin=A*17, beta.bin=B*513, gamma.bin=C*31 are fixed independently
of mutations. A special control replaces alpha's expected payload with 512 zero
bytes. tarfile.TarInfo emits USTAR headers; header+payload are block padded.
Constructed terminators consist of two 512-byte zero blocks, without record padding.

The concatenated TAR and concatenated gzip cases decode to exactly identical TAR
bytes. The former compresses those bytes as one gzip member. The latter compresses
two independently terminated TAR byte strings separately, then joins their gzip
members. Each fixture passes GNU gzip -t and -dc, plus exact equality with its
constructed TAR. GNU tar reads that fully decoded input from stdin. Thus a reader
stopping early cannot hide a gzip trailer error in this experiment.

GNU tar is invoked with --list or --extract --to-stdout, each with/without
--ignore-zeros, and --file -. Python iterates TarInfo objects and reads each
extractfile object fully, with ignore_zeros False/True. No name re-lookup.
LC_ALL=C and an otherwise minimal subprocess environment exclude TAR_OPTIONS.

Invalid-middle-header flips byte 1024, the first name byte of beta's header,
without updating its checksum. Its payload is intact. The missing-member fixture
removes beta's entire header and padded payload. Corruption and removal happen
BEFORE gzip compression. A valid gzip checksum therefore correctly covers the
altered TAR bytes; this does not show gzip failing to detect transport bit rot.

## Results and interpretation
Both default readers stop after alpha on concatenated TARs, even after every
outer gzip member was checked. The one-zero-gap case also returns alpha; GNU tar
warns but exits 0. Both ignore-zero modes reach all three files in these cases.

For the invalid middle header, GNU tar recovers alpha and gamma but exits 2 in
both modes. Python default returns only alpha without an exception; ignore_zeros
returns alpha and gamma without an exception. It is a salvage policy, not a
whole-input validation certificate. Pinned CPython next() treats invalid headers
after the first differently from invalid initial headers (a negative test covers
the latter). A structurally clean archive missing beta passes all readers but
fails every independently fixed recovery expectation.

Missing terminal zero blocks do not prevent full output on these builds.
A zero-filled payload is preserved: its position inside an entry matters.
Do not globally remove zero blocks to combine archives; this would remove data.

Listings compare names only. GNU stdout extraction compares the concatenated
payload stream, not per-member boundaries. Python compares complete name-to-byte
mappings. The JSON retains these distinct scope labels, all commands, statuses,
diagnostics, outputs, header offsets, expected hashes, source/binary hashes and
UTC generation time. These are API observations, not a trace of physical reads.

## Primary-source review (accessed 2026-10-21)
- GNU tar 1.35 Ignore-Zeros: https://www.gnu.org/software/tar/manual/html_node/Ignore-Zeros.html
  Default stopping and explicit continuation past zero blocks.
- GNU tar 1.35 concatenate: https://www.gnu.org/software/tar/manual/html_node/concatenate.html
  Byte concatenation retains terminators; --concatenate removes the target marker.
  It is not an input-archive validator.
- GNU gzip Advanced usage: https://www.gnu.org/s/gzip/manual/html_node/Advanced-usage.html
  Concatenated gzip members decode in sequence.
- RFC 1952 sections 2.2/2.3.1: https://www.rfc-editor.org/rfc/rfc1952.html
  Compression-member framing is separate from the decoded container's framing.
- Python 3.12 TarFile: https://docs.python.org/3.12/library/tarfile.html#tarfile.TarFile
  ignore_zeros skips empty AND invalid blocks; it is intended for salvage.
- CPython v3.12.3 TarFile.next, lines 2397-2416:
  https://github.com/python/cpython/blob/v3.12.3/Lib/tarfile.py#L2397
  Reviewed control flow against observations, not just the API summary.
  Distribution module hash is in results.json; no byte identity to upstream claimed.

## Scope and rights
All payloads and experiment code are authored for this test; no third-party
archive or source code is redistributed. This note synthesizes linked primary
documentation. Existing archive-member, gzip and archive-recovery analysis are
extended; no new term, article, schema or claimed novelty is needed.
No hostile input, sparse/PAX extensions, compression error timing, disk extraction,
multi-volume tapes, throughput, filesystem durability or modern-version survey.
An independently retained inventory plus per-entry contents is the recovery
oracle; a manifest reconstructed from the incomplete archive is not independent.

## Payload acceptance example
The separate acceptance.py demonstration derives 16 decisions from the retained
Python observations. It does not rerun readers or replace the 48 observations.
The expected set comes from the fixture's original PAYLOADS constants, not its
surviving entries. Require successful completion, exact literal-name coverage,
no duplicate names, and matching per-file sizes and SHA-256 digests.

    python3 -B acceptance.py --output acceptance-replay.json
    python3 -B -m unittest -v test_acceptance.py

Malformed records raise ValueError. Empty expected and observed sets can match,
but an empty observation cannot satisfy a nonempty expectation. Reconstructing
the expected set from surviving files defeats the check; a regression test shows
this limitation explicitly. The demonstration does not authenticate either input,
parse an arbitrary archive, verify metadata, normalize paths, enforce a trailing
data policy, or implement BagIt. A passed result is payload acceptance at this
scope, not whole-archive validation or an operational restore certificate.

RFC 8493 (BagIt 1.0), sections 3 and 5.4, distinguishes complete membership from
verified checksums and requires additional protection for active attacks:
https://www.rfc-editor.org/rfc/rfc8493.html

Elizabeth D. Zwicky's "Further Torture: More Testing of Backup and Archive
Programs", LISA 2003, pp. 7-10 and 13, supplies historical method context:
https://www.usenix.org/legacy/event/lisa03/tech/full_papers/zwicky/zwicky.pdf
Generated filesystem cases were restored and compared for content and metadata.
This convenience sample of then-current systems is not a present-day failure
rate; its configuration sensitivity motivates explicit build and option records.
Our in-memory payload experiment does not replicate its filesystem tests.
