Repository navigation
fix(lha): implement the real -lh2- format (clean-room) - #152
Merged
Merged
Conversation
Trigger: any `-lh2-` stream, in either direction. Effect: the codec was an LZHUF variant with a 510-symbol length alphabet and a 14-symbol bit-length position tree, which is not the -lh2- format: it could not decode real -lh2- archives, and LHa could not decode what it wrote. Our own round-trip tests could not notice. Fix: rewrite dynamic_huff.rs clean-room from a written functional specification of the format: a 286-symbol C-tree (literals, lengths 3..=31, and an escape followed by 8 raw length bits), a P-tree over `P >> 6` that grows by one symbol per 64 output bytes plus 6 raw low bits, with its root sentinel and separate update counter, and an 8 KiB space-filled window. The encoder caps lengths at 256 and distances at the bytes already output; the decoder accepts lengths up to 287. Tests: the spec's vectors (initial codes, adaptation trace, five streams encoded and decoded bit-exactly, a 4 MB random token stream that rebuilds both trees, checked by SHA-256), an oracle-verified fixture, and an opt-in conformance test that has LHa for UNIX (`COMPCOL_LHA`, or `lha` on PATH if it is LHa for UNIX) test and extract our lh1, lh2 and lh4..lh7 output. The fuzz target now drives lh2 too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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.
Replaces #146, which reproduced LHa for UNIX's tree rules from a reading of its source (a licensing problem for this MIT crate).
Problem
Our
-lh2-encoder and decoder only agreed with each other. The codec used a 510-symbol length alphabet, a 14-symbol bit-length position code and Okumura's LZHUF tree rules, none of which is the-lh2-format. It could not decode real-lh2-data, and LHa could not decode what it wrote.Clean-room process
master. It never saw fix(lha): make -lh2- match the LHarc format (needs a licensing decision) #146, the LHa source or the spec writer's context.Fix
P >> 6and grows by one symbol per 64 output bytes. It keeps LHa's root sentinel and its separate update counter, and the low 6 bits follow raw.Tests
COMPCOL_LHA, or fromlhaonPATHonly if it reports itself as LHa for UNIX. Otherwise the test skips; Homebrew'slhais Lhasa, which can't decode-lh2-, so it skips there.decoder_lhafuzz target now covers lh2.Results:
COMPCOL_LHA: all pass.cargo fmt --checkand clippy with-D warnings: clean.Not verified
-lh2-archives, and LHa for UNIX can decode-lh2-but not create it. Compatibility is shown against its decoder only.🤖 Generated with Claude Code