Repository navigation
feat(streaming): bounded, resumable LZ77 decoder for R2004-family pages - #246
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
DrunkOnJava
enabled auto-merge (squash)
October 26, 2026 09:49
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f302cbfd3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Lz77Decoder decodes one §4.7 stream from any prefix of its compressed bytes into an output slice of any size, and can pause between any two calls. Its only page state is a fixed 0xC000-byte window: with the crate's measured distance rules (+0x4000 for 0x10-0x1F, +1 otherwise, bit 3 of 0x12-0x1F as distance bit 14) no back-reference reaches further, so no page, including a system page with no declared cap, needs more. The declared decompressed size is a hard ceiling; reserved opcodes, distances before the first byte, overruns and streams cut before 0x11 are typed terminal errors. It compiles in the no_std, no-allocator kernel natively and for wasm32, bounded at WINDOW + 128. Lz77Checkpoint carries the opcode cursor, pending run, totals and the last min(produced, 0xC000) output bytes under a CRC-32; restore checks length, version and CRC before copying and then requires a reachable state. stream_lz77 decodes every compressed page of an R2004-family file (page map, section map, every LZ77 data page). verify_lz77.py runs it on the four canonical R2004-family fixtures and every R2004, R2010 and R2013 file in the pinned nextgis/dwg_samples commit: 25 files, 266 pages, 6,097,392 bytes, equal to lz77::decompress and to an independent Python parse (length, CRC-32, bytes consumed through 0x11). Fixed and proptest schedules down to one byte in and out reproduce the output; fresh-process resume inside the largest data page leaves no source byte read twice and no output duplicated; corrupt, truncated and resealed checkpoints and four stream corruptions end in their named errors. It runs in the required Streaming E2E job. Every AutoCAD-written page decompresses to its declared size and every stream ends 11 00 00; the crate's writer does neither (recorded on #163). Refs #205, #207
A CRC-valid decoder checkpoint may carry any consumed count; restore only required it to be non-zero. The next literal or opcode byte then added to it unchecked: a panic in debug builds, a wrapped input position in release. consumed is now accumulated with checked_add before any state moves, and the overflow is StreamError::CounterOverflow, terminal like every other decoder error. Audit of every restored counter: produced cannot pass its limit, since restore and each transition keep every pending run within limit - produced; acc is saturating and bounded by the limit; count and distance are bounded by consistent(). The walk cursors are bounded by consistent() against the verified u32 locators, and both header parsers are rebuilt by replay. stream_lz77 gains --decode-checkpoint <path> --input <hex>, which feeds a restored decoder directly, and its own resume check no longer trusts the caller file's counters. verify_lz77.py now forges consumed = 2^64 - 1 in a literal run and at an opcode (both end in CounterOverflow, with no panic) and decodes a literal run that ends exactly at a limit of 2^64 - 1. Reported by the review on #246.
DrunkOnJava
force-pushed
the
feat/streaming-lz77
branch
from
October 26, 2026 10:12
7abb032 to
b05686f
Compare
This was referenced Oct 27, 2026
DrunkOnJava
added a commit
that referenced
this pull request
Oct 28, 2026
… to what landed (#205, #206, #207) (#400) The ledger stopped at the header and the R13-R2000 walk, and the README's checkpoint contract described the header checkpoint alone and said full object and decompression checkpoints remain open. Both now cover the ten checkpoint kinds on main and the walkers of #240, #246, #260, #276, #299, #312, #333, #340 and #363, the perf series #360 to #366, and cite the evidence files of Streaming E2E run 40532346151. What was not measured is marked NOT MEASURED.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
streaming::Lz77Decoderis a bounded, resumable decoder for the R2004-family LZ77 dialect: it decodes one compressed page from any prefix of its bytes into an output slice of any size, pauses between any two calls, and can be checkpointed mid-page and resumed in a fresh process. Advances #205 (R2004+ decompression path) and #207 (decompression checkpoints); neither closes.Spec reference
ODA Open Design Specification for .dwg files v5.4.1, §4.7 (compression), with the page framing of §4.3 (system pages) and §4.5/§4.6 (data pages) used only to locate the streams under test.
lz77::decompress, measured against AutoCAD-written files: distances are one more than §4.7's text (+0x4000for0x10–0x1F,+1otherwise), and bit 3 of an0x12–0x1Fopcode is bit 14 of the distance. The largest distance is therefore0xBFFF, so a fixed0xC000-byte window decodes any page, including system pages whose declared size has no cap. State is that window plus 80 bytes (49,232 bytes measured on aarch64), compile-time bounded atWINDOW + 128in theno_std, no-allocator kernel, native andwasm32-unknown-unknown.Lz77Overrun, checked before anything is written). A reserved opcode isLz77Opcode, a distance before the first output byteLz77Offset(each with its input position), and a stream cut before0x11isLz77Truncatedfromend_of_input(). Errors are terminal; output is provisional until the caller's commit point.Lz77Checkpoint: opcode cursor, pending copy or literal run, totals, limit and the lastmin(produced, 0xC000)output bytes under a CRC-32 (54 + kept + 4bytes, at most 49,210; 29,754 for a full0x7400page). Restore checks length, version and CRC before copying anything, then requires a statedecodecan reach.Test plan
Measured on the rebased commit:
python3 tools/streaming/check_invariants.pyand both kernel builds (native andwasm32-unknown-unknown).python3 tools/streaming/verify_lz77.py target/debug/examples/stream_lz77 target/debug/examples/streaming_schedules: the four canonical R2004-family fixtures and every R2004, R2010 and R2013 file atnextgis/dwg_samples@ff05d5a(21 files, fetched by sha256 with bounded retry fromtools/streaming/lz77-corpus.json, never committed): 25 files, 266 compressed pages (page map, section map, every LZ77 data page), 6,097,392 decompressed bytes. For every page the output length and CRC-32 equallz77::decompress, and output, CRC and bytes consumed through0x11equal an independent Python §4.7 parse. Four fixed input/output schedules (down to one byte in and one byte out, with Pending polls) reproduce every file; 128 proptest input schedules on each of three files. Fresh-process resume inside the largest data page at every call of the canonical page (41 stops) and 45–46 sampled calls ofline_2004,line_2010andline_2013: source reads and output of the two processes concatenate to the uninterrupted run's. Checkpoints taken in seven of the ten decoder modes; 63 bit flips, 63 truncations, an oversized input and nine resealed unreachable states are rejected. A reserved opcode, a distance before the first byte, an output past the declared size and a stream cut before the terminator each end in their named error.workflow_dispatchon stacked heads containing this commit (run 40296858014, run 40299178744). This head's tree is byte-identical to the locally verified one (7078b85).sample_AC1032.dwg(Establish the provenance of sample_AC1032.dwg, the one R2018 file #96, not fetchable): 53 pages equal tolz77::decompress.-D warnings, all targets),cargo doc -D warnings,build_fixturesbyte-identical.Measured on the corpus and recorded in the docs: every AutoCAD-written page decompresses to exactly its declared size, and every stream ends
11 00 00. The crate's writer does neither; that is recorded on #163 with the numbers.Not measured: R2018 in CI, pages larger than
0x7400, throughput. R2007 (§5.10) is not covered.tools/streaming/lz77-corpus.jsonpins the same nextgis commit the corpus-CI lane (#95) is pinning; that lane converges the manifests after this lands.Source-provenance declaration
Clean-room declaration. All code in this PR was written from scratch. The only sources consulted were this repository and the ODA's public Open Design Specification for .dwg files v5.4.1. The distance rules come from this repository's own
src/lz77.rs(whose provenance is recorded in CLEANROOM.md). No Autodesk SDK, ODA SDK (Drawings / Teigha), LibreDWG or other copyleft DWG implementation source, and no decompilation, was consulted. Spec citations are in the diff.