GHSA-v2m4-h57v-fr6w: stable-diffusion.cpp: Out-of-bounds read in safetensors loader: unvalidated data_offsets allow a tensor's byte range to extend past the end of the file
stable-diffusion.cpp is a pure C/C++ library for running diffusion model (Stable Diffusion, Flux, Wan, Qwen Image, Z-Image, and more) inference. Prior to master-764-e22272e, the safetensors loader in src/modelio/safetensorsio.cpp trusts each tensor's dataoffsets after checking only that nbytes equals end - begin. A crafted .safetensors file can declare a byte range beyond the file's data section, causing src/modelloader.cpp to consume an attacker-chosen length from an unchecked mapped-file offset. Loading the model can read adjacent process memory into tensor buffers or crash the process. This issue is fixed in master-764-e22272e.
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
stable-diffusion.cppto a version that resolves this vulnerability.Patch master-764-e22272e