Views
No views yet
safetensors crate) validates and rejects these malformed files, third-party parsers, custom loaders, or older versions that trust header metadata without validation may be vulnerable.[8 bytes: header_size (u64 LE)] [header_size bytes: JSON header] [remaining: raw tensor data]poc_oom_shape.safetensors (168 bytes)[1000000, 1000000] and dtype F32. A naive parser that allocates shape_product * dtype_size before reading data will attempt a 4 TB allocation, causing OOM or system instability.poc_huge_header.safetensors (27 bytes)header_size = 0xFFFFFFFF (4,294,967,295 bytes). A parser that does malloc(header_size) followed by read(header_size) will attempt to allocate 4 GB for the header alone.poc_overlapping.safetensors (243 bytes)tensor_a at offsets [0, 16] and tensor_b at offsets [8, 24]) share overlapping byte ranges. This can cause undefined behavior in parsers that create independent mutable views of the underlying data buffer.benign.safetensors (149 bytes)[4] float32 tensor for comparison.safetensors library (v0.7.0) correctly rejects all three malicious files:| File | Result |
|---|---|
poc_oom_shape.safetensors | SafetensorError: invalid shape, data type, or offset for tensor |
poc_huge_header.safetensors | SafetensorError: header too large |
poc_overlapping.safetensors | SafetensorError: invalid offset for tensor |
benign.safetensors | Loads successfully |
header_size bytes without an upper bound checkdata_offsets without validationTensorView::new() bypasses size validation.
In safetensors/src/tensor.rs, n_elements: usize = shape.iter().product() uses unchecked
multiplication (unlike validate() which uses checked_mul). See overflow_poc.rs for details.1pip install safetensors
2python generate_pocs.py