# DEFLATE: a restart candidate is not an accepted boundary

Finding `00 00 ff ff` does not establish where the original DEFLATE writer
intended decoding to resume. Even successful decoding through the remaining
bytes can follow a different interpretation of the input.

## Native observations

Run on 30 November 2026 with native zlib 1.3. All inputs below are synthetic
raw-DEFLATE streams. Each complete original was decoded and byte-compared
before attempting the candidate interpretation.

| Input | Scanner result | Following decode | Interpretation |
|---|---|---|---|
| Repeated payload, full flush | Z_OK | Z_STREAM_END, 4320 correct suffix bytes | Writer-created history-independent boundary |
| Same payload, sync flush | Z_OK | Z_DATA_ERROR without prior history | A flush marker alone did not remove the dependency |
| Literal marker inside a stored block | Z_OK | Z_STREAM_END, all input consumed, output DECOY | A valid alternative parse, not the original stored-block contents |

The first two streams contain two copies of
`storage-history-0123456789:` repeated 160 times. A control supplying the saved
history also decodes the sync-flush suffix correctly.

For the third case, the stored payload consists of a literal prefix, the marker
bytes, and the encoded bytes of a small raw stream for DECOY. In the original
interpretation those bytes are literal data. Scanning skips into them and treats
the inner stream as compression syntax. No random corruption was sampled.

## API and research context

zlib's Z_SYNC_FLUSH makes current output available without clearing history.
Z_FULL_FLUSH also resets that history. The matching byte pattern is therefore
not unique to an independent restart. inflateSync documents its result as a
candidate. [zlib 1.3 API](https://github.com/madler/zlib/blob/v1.3/zlib.h),
[implementation](https://github.com/madler/zlib/blob/v1.3/inflate.c).

Rapidgzip's design accepts a prefetched chunk at the end offset established by
the preceding chunk. Its seek index also retains offsets and a history window.
This is more information than a plausible header or marker. See Knespel and
Brunst, [Rapidgzip, HPDC 2023, sections 1.2-1.3 and 3](https://arxiv.org/html/2308.08955v1),
DOI 10.1145/3588195.3592992. These controls do not reproduce its benchmarks.

## Reproduce and inspect

Download [probe.c](probe.c), [run.py](run.py), [test_probe.py](test_probe.py)
and [results.json](results.json) into one directory. A C compiler, zlib
development headers, and Python 3.11 or later with zlib are required.

```sh
python3 -B run.py
python3 -B -m unittest -v test_probe.py
python3 -B -O -m unittest -v test_probe.py
```

`run.py --write` regenerates the recorded evidence. The JSON records every
encoded input, its SHA-256, expected complete output, candidate output, consumed
byte counts, writer flush offsets and library versions. Tests replay those
recorded inputs as well as regenerating controls. Compressor versions may choose
different encodings; semantic checks matter more than identical new encodings.

The probe is bounded to 65536 input and 131072 output bytes. It is not a recovery
utility. It uses raw mode, so no zlib or gzip wrapper checksum is being accepted.
A recovered suffix does not restore skipped bytes or authenticate them. The
examples establish possible behaviors, not their frequency in damaged archives.

[DEFLATE definition and related concepts](https://hesela.dev/terms/deflate/)
