Skip to content

fix(lha): make -lh2- match the LHarc format (re-land of #146) - #148

Closed
MagicalTux wants to merge 1 commit into
masterfrom
fix/lha-lh2-format-master
Closed

MagicalTux wants to merge 1 commit into
masterfrom
fix/lha-lh2-format-master

Conversation

@MagicalTux

Copy link
Copy Markdown
Member

Re-lands #146, which merged into fix/pre-0.7.4 instead of master.

#146 was stacked on #145, so its base branch was fix/pre-0.7.4. #145 was then rebase-merged into master. GitHub retargets a stacked PR only when its base branch is deleted, so #146 kept fix/pre-0.7.4 as its base and merged there. Apart from #146's own commit, that branch's tree is identical to master at b44654d, so this PR cherry-picks just that commit (f0b0e9c) onto current master. It applies cleanly; the lha tests, clippy (-D warnings, --features all) and fmt pass.

See #146 for the description.

🤖 Generated with Claude Code

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>
@MagicalTux

Copy link
Copy Markdown
Member Author

Closing: #146 is on hold over the LHa for UNIX provenance question, so it shouldn't be re-landed on master yet.

@MagicalTux MagicalTux closed this Oct 22, 2026
@MagicalTux
MagicalTux deleted the fix/lha-lh2-format-master branch October 22, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant