A cabinet is a CFHEADER, then one CFFOLDER for each folder,
then one CFFILE for each file, then the CFDATA blocks of each
folder. This page follows Microsoft’s “Microsoft Cabinet File Format” document from the
Cabinet SDK, which [MS-CAB] repeats. Numbers are little-endian; the format version is
1.3.
CFHEADER
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 4 | signature | MSCF (4D 53 43 46). |
4 | 4 | reserved1 | Zero. |
8 | 4 | cbCabinet | Size of this cabinet file in bytes. |
12 | 4 | reserved2 | Zero. |
16 | 4 | coffFiles | Offset of the first CFFILE from the start of the file. |
20 | 4 | reserved3 | Zero. |
24 | 1 | versionMinor | 3. |
25 | 1 | versionMajor | 1. |
26 | 2 | cFolders | Number of CFFOLDER entries. |
28 | 2 | cFiles | Number of CFFILE entries. |
30 | 2 | flags | See header flags. |
32 | 2 | setID | A number chosen at random, the same in every cabinet of a set. |
34 | 2 | iCabinet | This cabinet’s number in the set, from 0. |
36 | 2 | cbCFHeader | Only with cfhdrRESERVE_PRESENT: size of abReserve below, 0 to 60,000. |
38 | 1 | cbCFFolder | Same condition: size of the reserved area in each CFFOLDER, 0 to 255. |
39 | 1 | cbCFData | Same condition: size of the reserved area in each CFDATA, 0 to 255. |
| … | cbCFHeader | abReserve | Same condition: data for the application. The Cabinet SDK says its cabarc tool can reserve space for a code signature with its -s option (6,144 bytes for code signing) and that a signing utility fills it; it does not say where in the cabinet that space is. |
| … | ≤ 256 | szCabinetPrev | Only with cfhdrPREV_CABINET: file name of the previous cabinet, NUL-terminated. |
| … | ≤ 256 | szDiskPrev | Same condition: name of the disk holding it, for prompting the user. |
| … | ≤ 256 | szCabinetNext | Only with cfhdrNEXT_CABINET: file name of the next cabinet. |
| … | ≤ 256 | szDiskNext | Same condition: name of its disk. |
Without reserved areas or neighbours the header is 36 bytes. (The Cabinet SDK text
says once that cbCFData is absent when the reserve flag is set; that is a
slip, as the flag’s own definition and every reader include it.)
Header flags
| Value | Name | Meaning |
|---|---|---|
0001 | cfhdrPREV_CABINET | Not the first cabinet of a set: the previous cabinet and disk names are present. |
0002 | cfhdrNEXT_CABINET | Not the last cabinet of a set: the next cabinet and disk names are present. |
0004 | cfhdrRESERVE_PRESENT | The three reserve sizes and the header’s reserved area are present. |
All other bits are reserved.
CFFOLDER
A folder is a run of files compressed together as one stream.
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 4 | coffCabStart | Offset of the folder’s first CFDATA block, from the start of the file. |
4 | 2 | cCFData | Number of CFDATA blocks of this folder in this cabinet. |
6 | 2 | typeCompress | Compression of every block in the folder. See compression types. |
8 | cbCFFolder | abReserve | Reserved area, when present. |
Compression types
The low four bits are the method; the higher bits carry its parameter. The names
and masks below are from fdi.h, read 2026-11-13 in
Wine’s copy (a
reimplementation of Microsoft’s header; Microsoft’s own was not available to read). The
cabinet specification itself says only that the compression formats are defined in separate
documents, and its FCIAddFile text names only tcompTYPE_NONE and
tcompTYPE_MSZIP.
| Value or mask | Name | Meaning |
|---|---|---|
000F | tcompMASK_TYPE | Mask for the method. |
0000 | tcompTYPE_NONE | Stored: each block’s data is the bytes themselves. |
0001 | tcompTYPE_MSZIP | MSZIP: Deflate. |
0002 | tcompTYPE_QUANTUM | Quantum. libmspack says Quantum “has no documentation”; its folder data needs a trailing byte so the decompressor can realign, since Quantum blocks, unlike LZX blocks, can have an odd length. Its algorithm is not in the sources read. |
0003 | tcompTYPE_LZX | LZX, LZ77 with Huffman coding. |
000F | tcompBAD | Not a valid method; used inside the SDK for errors. |
00F0 | tcompMASK_QUANTUM_LEVEL | Quantum compression level, 1 to 7 (0010 to 0070), shift 4. |
1F00 | tcompMASK_QUANTUM_MEM | Quantum window, 10 to 21 (0A00 to 1500), shift 8: the window is 2n bytes. |
1F00 | tcompMASK_LZX_WINDOW | LZX window, 15 to 21 (0F00 to 1500), shift 8: the window is 2n bytes, 32 KiB to 2 MiB. |
So 1503 is LZX with a 2 MiB window, and 0001 MSZIP. Also from
fdi.h: tcompMASK_RESERVED E000 (the high 3 bits are reserved);
the quantum level and memory fields are read with shifts of 4 and 8, and for LZX the window field is
the same mask as Quantum’s memory field (1F00, shift 8). The LZX window decides the
number of position slots, see LZX.
LZX data
The cabinet document does not define LZX; the format is Microsoft’s separate “LZX Data Compression
Format” (1997), which the Cabinet SDK page reproduces and which is summarised here (read
2026-11-13), with corrections from libmspack’s lzxd.c. The cabinet requires that each
CFDATA block represent exactly 32,768 uncompressed bytes (the last block of a folder
may be smaller) and that a compressed block be at most 32,768 + 6,144 bytes. The window size is a
power of two from 215 to 221 and is not stored in the data (the folder’s
typeCompress gives it).
- Bit order. The bitstream is a sequence of 16-bit words, each stored low byte first, bits read from the most significant end. After each 32,768th output byte (and after the last block of a folder) the bit buffer is padded with 0 to 15 zero bits to a 16-bit boundary, and a match may not span a 32,768-byte boundary of the uncompressed data.
- Header. One bit: 0 means no preprocessing; 1 is followed by a 32-bit “file translation size” (high 16 bits first, then low 16) used by the x86 call translation below.
- Constants.
MIN_MATCH2,MAX_MATCH257,NUM_CHARS256,NUM_PRIMARY_LENGTHS7 (not defined in the specification, per libmspack),NUM_SECONDARY_LENGTHS249, main tree256 + 8 × NUM_POSITION_SLOTSelements, aligned offset tree 8 elements, pre-trees 20 elements. - Block types (3 bits): 0 undefined, 1 verbatim, 2 aligned offset, 3 uncompressed, 4 to 7 undefined.
| Window | 32K | 64K | 128K | 256K | 512K | 1 MB | 2 MB |
|---|---|---|---|---|---|---|---|
| Position slots per the specification | 30 | 32 | 34 | 36 | 38 | 40 | 42 |
| Position slots in the implementation (libmspack, Microsoft’s Java package) | 30 | 32 | 34 | 36 | 38 | 42 | 50 |
libmspack notes that the actual rule is “the first slot whose position base is at least the window size”, and that the document’s other tables already show 50 slots.
Blocks
- Block length. Every block begins with its type (3 bits) and the number of uncompressed bytes it covers (24 bits, 1 to 224 − 1), the length being written as 16 bits then 8 bits. (The document omits the length for uncompressed blocks; libmspack reads it there too.)
- Verbatim block. Then: a 20-element pre-tree (4 bits per element, 80 bits) and the path
lengths of the first 256 main tree elements; a second pre-tree and the lengths of the remaining main
tree elements (up to
256 + 8 × slots); a third pre-tree and the 249 length tree lengths; then the compressed literals. - Aligned offset block. As a verbatim block, plus an aligned offset tree of 8 elements of 3 bits each (24 bits, no further compression). The specification places it after the main tree; libmspack, matching real files, reads it before the main and length trees, right after the block length.
- Uncompressed block. After the type and length, 1 to 16 zero bits pad to a 16-bit boundary (a 16-bit word is consumed when already aligned); then the bitstream ends and bytes follow: R0, R1 and R2 as 4-byte little-endian numbers (each must be less than the window size), then the data. If the block length is odd, one padding byte follows the data before the next block.
- Tree lengths. A tree is sent as the difference from its previous lengths (the first
time, from all zeros), mod 17, with lengths 0 to 16 (0 means unused). Each pre-tree element codes: 0 to 16:
len = (previous + code) mod 17; 17: 4 bits then that many + 4 zero lengths; 18: 5 bits then + 20 zero lengths; 19: 1 bit (+ 4 repeats), then another pre-tree code gives the length, applied to those + 4 elements by the same difference rule. Trees are canonical (lower-numbered elements of equal length are further left); a tree needs at least 2 elements, but libmspack accepts an empty length tree in blocks without matches.
Matches
A main tree element below 256 is a literal. Otherwise e = element − 256;
length_header = e & 7 and position_slot = e >> 3. If
length_header is 7, the length is the length tree element + 7 + 2 (lengths 9 to 257, footer 0 to
248); otherwise length_header + 2 (2 to 8). Offsets:
- Slot 0 means R0, slot 1 means R1 (swap R0 and R1), slot 2 means R2 (swap R0 and R2). Other offsets shift R2 ← R1 ← R0 ← new offset. R0, R1, R2 start as 1, 1, 1. The formatted offset is the real offset + 2 (so offsets are displaced by 3 from the code and 1 is the closest).
- Footer bits per slot: slots 0 to 3: 0; slots 4 to 35:
floor(slot / 2) − 1(1, 1, 2, 2, … 16, 16); slot 36 and above: 17. Base positions start 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, … andbase[i] = base[i − 1] + (1 << extra_bits[i − 1]); from slot 36 the base rises by 131,072 each step (36 is 262,144, 37 is 393,216, …, 49 is 2,097,152 − 131,072 = 1,966,080). The offset isbase + footer − 2. - In an aligned offset block, a footer of 3 or more bits is split: the lower 3 bits are coded with the aligned offset tree and the rest are verbatim bits (so 1 to 14 verbatim bits for the 17-bit footers). A footer of fewer than 3 bits is all verbatim, as in a verbatim block. (The specification says to read 3 bits when the footer has exactly 3, which libmspack corrects: only a Huffman symbol is read then.)
x86 call translation
When the header bit is set, the encoder first rewrites the 32-bit operand of each E8 (CALL) byte
from relative to absolute in each block of at most 32,768 input bytes; the decoder reverses it. With
curpos the position in the folder’s uncompressed data and file_size the translation
size, and abs the stored value: if abs ≥ −curpos and abs < file_size,
then the relative value is abs − curpos when abs ≥ 0, else abs + file_size;
other values are left alone. No translation is done in the last 6 bytes of a block (libmspack stops 10 bytes
from the end of a frame, noting that the document’s own pseudocode could touch the last 6 bytes), and
translation stops after the 32,768th frame of a folder.
CFFILE
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 4 | cbFile | Uncompressed size of the file. |
4 | 4 | uoffFolderStart | Where the file starts in its folder’s uncompressed data. |
8 | 2 | iFolder | Index of the folder, from 0, or a continuation code. |
10 | 2 | date | ((year − 1980) << 9) + (month << 5) + day. |
12 | 2 | time | (hour << 11) + (minute << 5) + seconds ÷ 2. |
14 | 2 | attribs | See attributes. |
16 | … | szName | The file name and path, NUL-terminated. Folders are separated by \. |
Folder index codes
| Value | Name | Meaning |
|---|---|---|
FFFD | ifoldCONTINUED_FROM_PREV | The file starts in the previous cabinet; its data is in folder 0 of this one. |
FFFE | ifoldCONTINUED_TO_NEXT | The file continues into the next cabinet; it is in the last folder here. |
FFFF | ifoldCONTINUED_PREV_AND_NEXT | The file comes from the previous cabinet and goes on into the next; this cabinet’s single folder holds its middle. |
Attributes
| Value | Name | Meaning |
|---|---|---|
01 | _A_RDONLY | Read-only. |
02 | _A_HIDDEN | Hidden. |
04 | _A_SYSTEM | System file. |
20 | _A_ARCH | Changed since the last backup. |
40 | _A_EXEC | Run the file after extracting it. |
80 | _A_NAME_IS_UTF | szName is UTF-8; otherwise it is in the system’s code page. |
All other bits are reserved.
CFDATA
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 4 | csum | Checksum of the block, or 0 for none. |
4 | 2 | cbData | Bytes of compressed data in this block. |
6 | 2 | cbUncomp | Uncompressed size of the block, at most 32,768; only the folder’s last block may be smaller. 0 when the block is split and continues in the next cabinet. |
8 | cbCFData | abReserve | Reserved area, when present. |
| … | cbData | ab | The compressed data. LZX blocks may be up to 32,768 + 6,144 bytes. |
Checksum
The checksum XORs 32-bit words together (CSUMCompute in the SDK document;
libmspack’s cabd_checksum does the same). Start from a seed; take the data four bytes
at a time as little-endian words and XOR each into the sum. The last one to three bytes form one
more word, but not low byte first: the first leftover byte goes in the highest
position used. With 3 bytes b0 b1 b2 the word is
(b0 << 16) | (b1 << 8) | b2; with 2 bytes (b0 << 8) | b1;
with 1 byte b0. That word is XORed in. (The reference code builds it with a
fall-through switch: case 3 shifts the first byte by 16, case 2 by 8, case 1 by 0.)
- Sum the
abbytes with seed 0. - Sum the block header from
cbDatato the end ofabReserve, with the first result as the seed. The result iscsum.
A block split across two cabinets has a checksum in each part: the first part has
cbUncomp = 0, the second has the full uncompressed size, and each covers
its own bytes and header. Microsoft’s extractors do not check the sum.
MSZIP blocks
In an MSZIP folder each block’s data is the two bytes 43 4B
(CK) followed by Deflate data (RFC 1951) that produces exactly
cbUncomp bytes. The Deflate history carries on from one block to the next
in the same folder, so the blocks must be decoded in order. This comes from
Microsoft’s separate “MSZIP Data Compression Format” document, which the Cabinet SDK page
says is a different document from the cabinet specification. libmspack’s
mszipd.c (read 2026-11-13) implements the same: it looks for C then
K at the start of each block, decodes Deflate with a 32,768-byte window
(MSZIP_FRAME_SIZE) that persists across blocks, and states that “MSZIP is equivalent
to the deflate method”.
Spanning several cabinets
When a folder does not fit, its data goes on in the next cabinet: the last block may
be split there, the next cabinet starts with a folder that continues it, and the
files involved use the continuation codes. Every cabinet of the
set shares setID and numbers itself with iCabinet.