An LHA archive is a run of entries, each a header and the compressed data, ended by a
single 00 byte where the next header would start. Every header has the
method ID at offset 2 and the header level at offset 20; the level decides the rest.
This page follows the header notes of LHa for UNIX
(header.doc.md,
the English translation of Masaru Oki’s 1992 notes and Yoshizaki’s lhx.doc) and the sources of the
Lhasa library (lib/ext_header.c,
lha_file_header.c, lh_new_decoder.c, lh1_decoder.c,
lzs_decoder.c, lz5_decoder.c, tree_decode.c and
bit_stream_reader.c), all read 2026-11-13. Numbers are little-endian.
Header levels
| Offset | Level 0 | Level 1 | Level 2 | Level 3 |
|---|---|---|---|---|
0 | Header size, 1 byte | Header size, 1 byte | Total header size, 2 bytes | Word size, 2 bytes, always 4 |
1 | Header checksum, 1 byte | Header checksum, 1 byte | ||
2 | Method ID, 5 characters, such as -lh5- | |||
7 | Packed size, 4 | Skip size, 4: packed size plus all extended headers | Packed size, 4 | Packed size, 4 |
11 | Original size, 4 | |||
15 | MS-DOS time, 2, and date, 2 | MS-DOS time, 2, and date, 2 | Unix time, 4 | Unix time, 4 |
19 | MS-DOS attribute, 1 | Fixed 20, 1 | Reserved, 1 | Reserved, 1 |
20 | Level 00 | Level 01 | Level 02 | Level 03 |
21 | Name length, 1; name; file CRC-16, 2; optional extension area | Name length, 1; name; file CRC-16, 2; OS ID, 1; next extended header size, 2 | File CRC-16, 2 | File CRC-16, 2 |
23 | OS ID, 1 | OS ID, 1 | ||
24 | Next extended header size, 2 | Total header size, 4 | ||
26 / 28 | Extended headers (2-byte sizes) | Next extended header size, 4, then extended headers (4-byte sizes) | ||
- Level 0 is the LHarc and LArc layout. The header size counts the
bytes after the checksum byte; the name holds the whole path with
\separators. Anything between the CRC and the end of the header is an extension area (below). - Level 1 keeps the level 0 layout, so old programs can still extract the data, and adds extended headers after it. They are counted in the skip size, not in the header size, so the true packed size is the skip size minus their lengths. The base header’s name is usually the file name only, with the folder in an extended header.
- Level 2 has a 2-byte total size covering the base header and all extended headers, and no name in the base header: the name is always in extended headers. A level 2 header’s CRC is in the common extended header.
- Level 3, used by some later writers, is level 2 with 4-byte sizes: the word size at offset 0, a 4-byte total header size at 24, and 4-byte extended header sizes.
Header checksum and CRC
Levels 0 and 1: the checksum byte is the sum of the base header’s bytes from offset 2 to its end (the header size says where), keeping the low 8 bits. It does not cover the extended headers.
The file CRC, and the header CRC in a common extended header, is CRC-16 with
polynomial A001 (the reflected form of 8005, often called
CRC-16/ARC), starting from 0. For the header CRC, the two CRC bytes count as zero
while it is worked out.
Times
Levels 0 and 1 store an MS-DOS time word then date word, in local time: date bits 15 to 9 year − 1980, 8 to 5 month, 4 to 0 day; time bits 15 to 11 hour, 10 to 5 minute, 4 to 0 seconds ÷ 2. Levels 2 and 3 store Unix time, seconds since 1970 UTC.
Level 0 extension area
Some writers put more bytes after the CRC of a level 0 header. When the first byte
is the Unix OS ID (U), the area is at least 12 bytes: a byte that must be
00, a 4-byte Unix time, and in its last 6 bytes the permissions, user ID
and group ID, 2 bytes each. OS-9 writers use their own 22-byte layout with OS-9
permissions. These layouts are from Lhasa’s source.
Extended headers
In levels 1 to 3 each extended header is a type byte, its data, and the size of the next extended header (2 bytes, or 4 in level 3); a size of 0 ends the chain. A size counts the whole extended header: type, data and the next-size field.
| Type | Name | Data |
|---|---|---|
00 | Common | CRC-16 of the whole header, then optional information. |
01 | File name | The file name, without a path; no NUL. |
02 | Directory name | The folder path, with FF bytes between the folder names and normally after the last one. Lhasa adds a missing final FF because Amiga LHA 1.22 left it out. |
39 | Multi-disc | Lhasa names the number (LHA_EXT_HEADER_MULTI_DISC) but has no parser for it, so it is skipped; header.doc.md does not list it. No layout is in the sources read. |
3F | Comment | A comment. |
40 | MS-DOS attribute | Not in header.doc.md or Lhasa, so no layout is confirmed by any source read. (Earlier text here gave it as the 2-byte MS-DOS attributes; that came from no source read and is withdrawn.) |
41 | Windows timestamps | 24 bytes: creation, modification and access times, each a 64-bit Windows FILETIME (100-nanosecond units since 1601). |
42 | File sizes | 16 bytes: the 64-bit packed size, then the 64-bit original size, for files over 4 GiB. |
50 | Unix permissions | 2 bytes: the Unix mode. |
51 | Unix group and user ID | 2-byte group ID, then 2-byte user ID. |
52 | Unix group name | Text. |
53 | Unix user name | Text. |
54 | Unix time | 4 bytes: modification time, seconds since 1970. LHa for UNIX writes it only in level 1 headers, which otherwise have an MS-DOS time. |
CC | OS-9 | OS-9 attributes; Lhasa reads the 2-byte permissions at offset 7 of the data and does not decode the rest. |
header.doc.md calls types 00 to 3F “OS-independent” and
gives the Unix-dependent ones as 50 to 54. Lhasa also parses 41,
42 and CC, and ignores any other type (it reports it as unknown and moves on by
the size). No source read describes types such as 40, 7D, 7E,
7F or FF. Minimum data lengths that Lhasa requires before it will decode a type:
common 2 bytes, file name 1, directory 1, Windows times 24, file sizes 16, Unix permission 2, UID/GID 4,
group 1, user 1, Unix time 4, OS-9 12. The filename header’s / characters are replaced by
_. header.doc.md also records that the Unix user and group name headers
(52, 53) were not written by LHa for UNIX 1.14 and were added in 1.14i behind a
build option, and that where they exist they win over the numeric IDs; Lhasa notes that it knows of no tool that
writes them.
The common header (00) holds the CRC-16 of the whole header; to compute it the CRC bytes are
taken as zero. Lhasa notes that some platforms (OS/2, Unix) put extra data in the common header, which it
does not decode. The level 0 extension areas, from Lhasa: for Unix (and OS-9/68K, which makes a similar
area) the first byte is the OS letter, the second must be 00, bytes 2 to 5 a Unix time, and the last
6 bytes the permissions, user ID and group ID (OS-9/68K writes the time twice, so Lhasa reads from the end); a
typical one is 55 00 00 3b 3d 4b 80 81 e8 03 e8 03. An OS-9 area (22 bytes) has CC at
offset 9, bytes 1–2 equal to bytes 17–18, and the 2-byte permissions at offset 1. PMarc (-pm)
level 0 headers can hold a comment in that area, so Lhasa does not parse it there.
Symbolic links are stored with the method -lhd- and the name
link|target, split at the |.
Method IDs
| ID | Window | Longest match | Coding |
|---|---|---|---|
-lh0- | – | – | Stored |
-lh1- | 4 KiB | 60 | LZSS with dynamic (adaptive) Huffman; fixed coding of positions. LHarc 1.x’s method. |
-lh2- | 8 KiB | 256 | Dynamic Huffman. Experimental, rarely seen. |
-lh3- | 8 KiB | 256 | Static Huffman. Experimental, rarely seen. |
-lh4- | 4 KiB | 256 | Static Huffman with better coding of positions and trees. |
-lh5- | 8 KiB | 256 | As -lh4-. LHA 2.x’s default and the most common method. |
-lh6- | 32 KiB | 256 | As -lh4-. |
-lh7- | 64 KiB | 256 | As -lh4-. |
-lhd- | – | – | Not a method: the entry is a folder (or a link), with no data. |
-lzs- | 2 KiB | 17 | LArc’s LZSS method. |
-lz4- | – | – | LArc: stored. |
-lz5- | 4 KiB | 17 | LArc’s LZSS method. |
-pm0-, -pm1-, -pm2- | PMarc, an archiver for MSX-DOS with the same headers: stored and two compression methods, not described here. | ||
LHARK, a DOS archiver, wrote -lh7- with a different method in level 1
archives; Lhasa tells them apart by context and calls that method
-lk7-.
OS IDs
| Character | System |
|---|---|
M | MS-DOS |
2 | OS/2 |
9 | OS-9 |
K | OS-9/68K |
3 | OS/386 |
H | Human68K |
U | Unix |
C | CP/M |
F | FLEX |
m | Macintosh |
R | Runser |
This is the list in LHa for UNIX’s header notes (“as of now, reserved the following IDs”). Lhasa’s
lha_file_header.h adds: w Windows 95, W Windows NT, A
Amiga, a Atari, J Java, T TownsOS, a space (20) LHARK, and
0 for unknown. No register of all values exists in the sources read.
Compressed data
From Lhasa’s decoder sources. All the Huffman-based methods read bits most significant bit
first: a byte’s top bit is the first bit, and a multi-bit value is read high bit first. Copy
commands copy from a ring buffer of earlier output; every ring buffer starts filled with spaces
(20) except where noted. Copying is byte by byte, so a copy can overlap its own output.
-lh4-, -lh5-, -lh6-, -lh7-
One decoder with different sizes (the ring buffer in Lhasa is larger than the window; the window sizes in
the method table are the limits the writer uses, set as RING_BUFFER_SIZE / 4 for lh4 and
/ 2 for the others in Lhasa’s decoder table; -lh4- is otherwise
identical to -lh5-):
| Method | History bits in Lhasa | Offset-table count field (OFFSET_BITS) | Window |
|---|---|---|---|
-lh4- | 14 | 4 | 4 KiB |
-lh5- | 14 | 4 | 8 KiB |
-lh6- | 16 | 5 | 32 KiB |
-lh7- | 17 | 5 | 64 KiB |
The stream is a series of blocks. Each block starts with:
- A 16-bit count of commands in the block.
- Temp table (the code-length code for the next table): 5 bits n. If n is 0, 5 more bits name the only symbol (zero-length code). Otherwise n code lengths (at most 31), each a length value; after the third length a 2-bit count of further lengths to set to 0 is read.
- Code table (510 symbols: 0–255 are literal bytes, 256–509 copy lengths): 9 bits n. If 0, 9 more bits name the only symbol. Otherwise symbols are read through the temp table until n lengths are filled: a value 0 skips one symbol; 1 skips 3 to 18 (4 bits + 3); 2 skips 20 or more (9 bits + 20); any larger value v sets the length v − 2. Skipped symbols have length 0.
- Offset table:
OFFSET_BITSbits n (as the table), then if 0 a single code of that many bits, otherwise n length values.
A length value is 3 bits; if it is 7, further bits are read, each 1 adding 1 to the value, until a 0.
Trees are canonical-style: the codes are assigned by length, shorter first, and within one length in symbol order,
filled left to right in the tree (a 0 bit goes to the left branch). A command is one code from the code table: a
value below 256 is a literal; otherwise the copy length is code − 256 + 3 (3 to 256), followed by an offset code from
the offset table giving a bit count b: b = 0 gives offset 0, 1 gives 1, and larger b reads
b − 1 more bits and adds 2b−1. The copy starts at current position − offset − 1 in the ring buffer.
When the block’s commands are used up, a new block starts. Lhasa also has a variant for LHARK’s own
-lh7- (-lk7-) with a different offset and length coding, and a larger
-lhx- (Unlha32’s extension, 220 history) that reuse the same structure; neither is documented here.
-lh1-
Adaptive Huffman coding of 314 codes (0–255 literals; 256–313 copy lengths, length = code − 256 + 3, so 3 to 60) with a
4,096-byte ring buffer. The tree starts balanced with every code at frequency 1, with the leaves at the end of a node table
and each internal node the sum of its two children. After each code is decoded its leaf’s frequency and those of its ancestors
are incremented, moving the node to the left end of its group of equal frequencies and keeping the table ordered; reading a bit chooses
between a node’s two children (bit 1 the lower-indexed one). When the root’s frequency reaches 32,768 the tree is rebuilt with every leaf’s
frequency halved (rounded up). A copy’s offset is a fixed code: the next 8 bits are looked up in a table giving a top part of 3 to 8 bits
(the number of codes with 3, 4, 5, 6, 7 and 8 bits being 1, 3, 8, 12, 24 and 16, assigned in order, 64 codes in all), then 6 low bits;
the offset is (top part << 6) | low bits, and the copy starts at position − offset − 1.
-lzs- and -lz5-
- -lzs-: 2,048-byte ring buffer, positions start at
2048 − 17. Each command begins with a bit: 1, then 8 bits, a literal; 0, then an 11-bit absolute ring buffer position and a 4-bit length (copy length = value + 2, 2 to 17). - -lz5-: 4,096-byte ring buffer, positions start at
4096 − 18, byte-oriented. A control byte gives eight commands, low bit first: 1 is a literal byte; 0 is a 2-byte copy (low byte of the absolute ring buffer position, then the high 4 bits of the position in the top nibble of the next byte and the length − 3 in its bottom nibble: length = nibble + 3, 3 to 18). The ring buffer starts with, for each byte value 0 to 255, 13 copies of it; then the bytes 0 to 255 ascending, then 255 down to 0; then 128 zero bytes, 110 spaces and 18 zeros. - The PMarc methods (
-pm0-,-pm1-,-pm2-) have decoders in Lhasa that are not described here.