Every 7z archive starts with a fixed 32-byte signature header. It identifies the file and points to the real header, which is written at the end of the archive after the packed data. All numbers in a 7z archive are little-endian. This page also describes the two kinds of number the rest of the format uses.
Fields
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
0 | 6 | bytes | kSignature | Always 37 7A BC AF 27 1C: the characters 7z and four fixed bytes. |
6 | 1 | byte | Major | Major format version. Always 0. |
7 | 1 | byte | Minor | Minor format version. The current description gives 4; 7-Zip writes 4, older versions wrote 2 or 3, and readers accept any minor version with major 0. |
8 | 4 | UINT32 | StartHeaderCRC | CRC-32 of the next 20 bytes (offsets 12 to 31). |
12 | 8 | REAL_UINT64 | NextHeaderOffset | Where the end header starts, counted from the end of this signature header (offset 32), not from the start of the file. |
20 | 8 | REAL_UINT64 | NextHeaderSize | Size of the end header in bytes. |
28 | 4 | UINT32 | NextHeaderCRC | CRC-32 of the end header’s bytes. |
The CRC is the usual CRC-32 of ZIP and gzip (polynomial EDB88320,
reflected, starting at FFFFFFFF and inverted at the end). The end header
starts with a property ID: 01 for a plain
header, or 17 for an encoded
(compressed) header, which is the usual case.
While 7-Zip is still writing an archive, the start header holds zeros. An archive
whose NextHeaderOffset, NextHeaderSize and
NextHeaderCRC are all zero was never finished, and a reader can only try
to recover the packed data. An empty archive has a zero-sized end header with a valid
CRC.
Numbers
REAL_UINT64 is a plain 8-byte little-endian number and
UINT32 a 4-byte one. Everywhere in the end header, counts, sizes and
indexes are written as UINT64, a variable-length number of 1 to 9 bytes.
The number of leading 1 bits in the first byte says how many more bytes follow; those
bytes are a little-endian number, and the bits left in the first byte are the high
part of the value.
| First byte | Bytes after it | Value | Largest value |
|---|---|---|---|
0xxxxxxx | 0 | xxxxxxx | 127 |
10xxxxxx | 1 | (xxxxxx << 8) + y | 214 − 1 |
110xxxxx | 2 | (xxxxx << 16) + y | 221 − 1 |
1110xxxx | 3 | (xxxx << 24) + y | 228 − 1 |
11110xxx | 4 | (xxx << 32) + y | 235 − 1 |
111110xx | 5 | (xx << 40) + y | 242 − 1 |
1111110x | 6 | (x << 48) + y | 249 − 1 |
11111110 | 7 | y | 256 − 1 |
11111111 | 8 | y | 264 − 1 |
y is the little-endian number in the following bytes. The specification
prints the first three rows and the last three; the rows for 3, 4 and 5 bytes follow
the same pattern. Examples: 05 is 5; 81 00 is 256;
C1 00 00 is 65,536.
Other types in the end header: BYTE; BIT arrays packed eight
to a byte, most significant bit first (the first item is bit 7 of the first byte, as
7-Zip reads them; the description does not say), padded to a whole byte; and
wchar_t names in UTF-16LE.
Archive layout
- Signature header (this page), 32 bytes.
- Packed streams: the compressed file data, starting at offset 32 plus the
PackPosof the main streams. - Packed streams for the headers: the compressed end header, when it is encoded.
- The end header at
32 + NextHeaderOffset: either a plainHeader, orkEncodedHeaderand the streams information needed to unpack the real header. See header and property IDs.
Example
The signature header of a small archive whose end header is 90 bytes long and starts 1,234 bytes after it:
37 7A BC AF 27 1C kSignature "7z" BC AF 27 1C
00 04 version 0.4
xx xx xx xx StartHeaderCRC, CRC-32 of the next 20 bytes
D2 04 00 00 00 00 00 00 NextHeaderOffset 1234 (end header at offset 1266)
5A 00 00 00 00 00 00 00 NextHeaderSize 90
xx xx xx xx NextHeaderCRC