Repository navigation
fix(lha): make -lh2- match the LHarc format (needs a licensing decision) - #146
Merged
Merged
Conversation
Trigger: any non-empty input encoded with Lh2 and stored in a .lzh archive as -lh2-, or a genuine -lh2- member fed to Lh2's decoder. Effect: `lha t` reported a CRC error for every archive we produced. Our encoder and decoder agreed only with each other: they used an invented 510-symbol length alphabet, a 14-symbol bit-length position class, and Okumura's LZHUF tree update, none of which is the -lh2- bitstream, so real -lh2- data could not be decoded either. Fix: implement the format LHA actually uses: a 286-symbol char tree (lengths 3..=31 direct, symbol 285 + 8 raw bits for longer matches), a position tree over pos >> 6 that starts as a single leaf and gains a symbol each time the output count passes a multiple of 64, followed by 6 raw low bits, and LHA's leader/block adaptive-Huffman update and rebuild rules for both trees (their node layout fixes every code bit). New tests have the lha CLI verify and extract our output for every LHA method (skipped when lha is absent), pin the lh2 bitstream with an lha-verified fixture, and check decoder reset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 22, 2026
Member
Author
|
Superseded by #152, a clean-room reimplementation: one agent wrote a code-free spec from the LHa for UNIX source, and a separate agent with a fresh context implemented #152 from that spec and black-box oracle testing alone. Note: this PR was merged into |
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.
Stacked on #145. This is kept out of that PR because of a provenance question, which is your call.
Problem
Our
-lh2-encoder and decoder only agreed with each other. The reallhatool (LHa for UNIX) fails its CRC check on any non-empty lh2 data we encode. Our implementation got three parts of the format wrong:pos >> 6) with a tree that grows as output is produced, then sends the low 6 bits raw. Ours coded a fixed 14-class bit length.Fix
The encoder and decoder are rewritten to the real format.
lha tnow reports CRC OK on our archives, andlha pgives back the original input.tests/lha.rsnow wraps each method's encoder output (lh1, lh2, lh4–lh7) in a.lzharchive and haslhaverify and extract it; the check is skipped whenlhaisn't installed. A 208-byte lh2 fixture covers machines withoutlha.The other LHA methods in this crate are documented as clean-room. To get every code bit right, this rewrite was written from a reading of the LHa for UNIX sources (
dhuf.c,slide.c), reproducing their tree-update and rebuild rules in new Rust code. LHa for UNIX has its own license with conditions, and the crate is MIT. The module docs now say the rules were "matched to the behaviour of the LHa for UNIX extractor".Options:
-lh2-returnError::Unsupportedinstead of producing data thatlharejects.Also: no tool available here can create lh2 data, so the decoder hasn't been tested on lh2 written by another encoder. It runs the same tree code that
lhaaccepts, so it is expected to work.🤖 Generated with Claude Code