Been looking into supporting a few more compression formats that I get requests for. Heard about libarchive, which purports to support RAR and LHA, along with a few others I care less about. Plus, it's apparently the library used by Windows and macOS for their in-built archive support. Must be great!
So I wire it up, figure out how to build and integrate it, then toss a few archives at it. The first RAR archive I throw fails to decompress 3 files for various reasons. The first LHA archive fails completely because it doesn't support the OG legacy -lh1- compression. I confirm that Windows fails the same way decompressing those from explorer. Total bust.
Then I start looking into LHA. It's an older format, can't be that bad. Found a nice repo with actually readable code in it, so I ported the code into my archiver architecture. First LHA I throw at it fails decompressing 3 files.
Ok, surely I messed something up. I pore over the ported code, looks good. Then download the binary from the repo and throw the same archive at it. It produces identical results. Fuck. Clearly the code in this repo is not 100% correct.
All right, further research shows that the OG source for the encoder/decoder has been long available. Dig it up on discmaster, as expected it's the usual terrible compression code, written more for speed than comprehension, with all single-letter variables and very little explanation of what's going on. But that's ok, I'm just experimenting here.
So I port that code into my archive structure, feed it the LHA in question and... it produces the same results as both my previous attempts and the repo I had found. Have I just found a cursed archive? Except 7zip can decompress the LHA successfully, so it's definitely not bad.
Well then, maybe the 7zip code can shed some light. So I look up the 7zip code on github, find the LHA logic and... the lh1 support is entirely commented out, and the decoder itself nowhere to be found. WTF? I'm so confused. Somewhere there must exist code that can extract this fucker, where is it???