Fanbase

cab/cab

version 1.0

Cabinet files of one stored file in one data block, plain or with a reserved header area, with offsets, sizes and the CFDATA checksum (no compression, no sets)

Format
Microsoft Cabinet (cab)
Authors
The Fandango Fuzzer Team
License
Apache-2.0
Fandango
>=1.3
Extensions
cab
Media type
application/vnd.ms-cab-compressed
Specification
https://learn.microsoft.com/en-us/previous-versions/bb417343(v=msdn.10)
Its files should decode
always
In the registry
specs/cab/cab/cab.fan

Use it

fanbase install cab
fandango fuzz -F cab -n 10

How it does

accepts 100%, covers 23.9%, 35/s. 1000 inputs, seed 1.

ParserAcceptsVersion
7zip100%25.01
cabextract100%cabextract version 1.11
libarchive100%bsdtar 3.7.4 - libarchive 3.7.4 zlib/1.3.1 liblzma/5.8.1 bz2
libarchive-cab-cov100%libarchive (Cabinet) 3.8.10

The spec says its files decode always: as expected.

libarchive-cab-cov

lines reached
23.9% of 1723
real files reach
28.3%
only the generated files
17 lines
only the real files
92 lines
22.9% after 1 inputs, 23.9% after 1000real files: 28.3%

Cite it

@software{fanbase_cab_cab_1_0,
  author  = {{The Fandango Fuzzer Team}},
  title   = {Microsoft Cabinet (cab/cab), a Fandango input specification},
  version = {1.0},
  url     = {https://github.com/fandango-fuzzer/fanbase},
  note    = {Fanbase registry, specs/cab/cab/cab.fan, sha256 f0700ab42f36},
}

Source

Source (110 lines)
# Microsoft Cabinet files of one folder, one file and one data block, stored
# (typeCompress 0, so the data is the file and cbData == cbUncomp == cbFile):
# CFHEADER, CFFOLDER, CFFILE and CFDATA. The header is plain, or declares a
# per-cabinet reserved area (RESERVE_PRESENT). The size of the cabinet, the
# offsets of the first CFFILE and of the data, the sizes and the CFDATA
# checksum are tied to the bytes by where constraints. All fields are
# little-endian.
#
# TODO:
# * No MSZIP, Quantum or LZX data, no cabinet sets (previous and next
#   cabinets), and only ever one folder, one file and one data block.
# * The folder and data reserve sizes are always 0.

import struct

# The CFDATA checksum: the XOR of the block's 32-bit little-endian words; the
# one to three bytes left over make one more word, the first of them the
# highest. The data is summed first, then cbData and cbUncomp.
def cab_cksum(data, seed):
    csum = seed
    n = len(data)
    cull = n // 4
    for i in range(cull):
        b = 4 * i
        csum ^= data[b] | (data[b + 1] << 8) | (data[b + 2] << 16) | (data[b + 3] << 24)
    rem = n % 4
    ul = 0
    base = cull * 4
    for i in range(rem):
        ul = (ul << 8) | data[base + i]
    csum ^= ul
    return csum & 0xffffffff

def cfdata_csum(ab, cb_data, cb_uncomp):
    c = cab_cksum(ab, 0)
    hdr = struct.pack('<HH', cb_data, cb_uncomp)
    return cab_cksum(hdr, c)

<start> ::= <cabinet>

<cabinet> ::= <header> <folder> <file> <data>

# CFHEADER: plain (flags 0), or with a reserved area (flags 0x0004). The
# offsets below are counted from the length of the header, whichever it is.
<header> ::= <header_plain> | <header_reserve>

<header_plain> ::= <sig> <resv4> <cb_cabinet> <resv4> <coff_files> <resv4> \
                   <ver_minor> <ver_major> <c_folders> <c_files> \
                   <flags_plain> <set_id> <i_cabinet>

<header_reserve> ::= <sig> <resv4> <cb_cabinet> <resv4> <coff_files> <resv4> \
                     <ver_minor> <ver_major> <c_folders> <c_files> \
                     <flags_reserve> <set_id> <i_cabinet> \
                     <cb_cfheader> <cb_cffolder> <cb_cfdata> <ab_reserve>

<sig>        ::= b'MSCF'
<resv4>      ::= b'\x00\x00\x00\x00'
<cb_cabinet> ::= <byte>{4}
<coff_files> ::= <byte>{4}
<ver_minor>  ::= b'\x03'
<ver_major>  ::= b'\x01'
<c_folders>  ::= b'\x01\x00'
<c_files>    ::= b'\x01\x00'
<flags_plain>   ::= b'\x00\x00'
<flags_reserve> ::= b'\x04\x00'
<set_id>     ::= <byte>{2}
<i_cabinet>  ::= b'\x00\x00'
# Only the cabinet has a reserved area: cbCFHeader is its length, and the
# folder and data reserves are 0.
<cb_cfheader> ::= <byte>{2}
<cb_cffolder> ::= b'\x00'
<cb_cfdata>   ::= b'\x00'
<ab_reserve>  ::= <byte>{1,16}

# CFFOLDER: one folder, stored
<folder> ::= <coff_cab_start> <c_cfdata> <type_compress>
<coff_cab_start> ::= <byte>{4}
<c_cfdata>       ::= b'\x01\x00'
<type_compress>  ::= b'\x00\x00'

# CFFILE: the one file fills the folder, from offset 0
<file> ::= <cb_file> <uoff_folder_start> <i_folder> <fdate> <ftime> \
           <attribs> <sz_name>
<cb_file>           ::= <byte>{4}
<uoff_folder_start> ::= b'\x00\x00\x00\x00'
<i_folder>          ::= b'\x00\x00'
<fdate>             ::= <byte>{2}
<ftime>             ::= <byte>{2}
# The attribute bits (read-only, hidden, system, archive, execute, name is
# UTF-8) are in the low byte
<attribs>           ::= rb'[\x00-\x7f]' b'\x00'
<sz_name>           ::= rb'[\x21-\x7e]{1,30}' b'\x00'

# CFDATA: one stored block
<data> ::= <csum> <cb_data> <cb_uncomp> <ab>
<csum>      ::= <byte>{4}
<cb_data>   ::= <byte>{2}
<cb_uncomp> ::= <byte>{2}
<ab>        ::= <byte>{1,64}

# Where the files and the data start, and how long the cabinet is
where <coff_files> == (len(bytes(<header>)) + len(bytes(<folder>))).to_bytes(4, 'little')
where <coff_cab_start> == (len(bytes(<header>)) + len(bytes(<folder>)) + len(bytes(<file>))).to_bytes(4, 'little')
where <cb_cabinet> == (len(bytes(<header>)) + len(bytes(<folder>)) + len(bytes(<file>)) + len(bytes(<data>))).to_bytes(4, 'little')
where <cb_cfheader> == len(bytes(<ab_reserve>)).to_bytes(2, 'little')
# The file is the data, stored
where <cb_file> == len(bytes(<ab>)).to_bytes(4, 'little')
where <cb_data> == len(bytes(<ab>)).to_bytes(2, 'little')
where <cb_uncomp> == len(bytes(<ab>)).to_bytes(2, 'little')
where <csum> == cfdata_csum(bytes(<ab>), len(bytes(<ab>)), len(bytes(<ab>))).to_bytes(4, 'little')