CVE-2026-70659: stable-diffusion.cpp: Heap out-of-bounds write in the imatrix loader (`load_imatrix`) via a duplicate tensor name
stable-diffusion.cpp is a pure C/C++ library for running diffusion model (Stable Diffusion, Flux, Wan, Qwen Image, Z-Image, and more) inference. From master-742-1a13107 until master-763-4fcc6fe, IMatrixCollector::loadimatrix in src/runtime/imatrix.cpp reuses the values and counts vectors for entries with the same tensor name but resizes them only when they are empty. An untrusted .imatrix file can provide a small nval for the first entry and a larger nval for a second entry with the same name, causing the accumulation loop to write attacker-controlled floating-point and integer values beyond both heap buffers. Loading the file through the --imat-in conversion path can corrupt the heap or crash the process before a model is required. This issue is fixed in master-763-4fcc6fe.
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
stable-diffusion.cppto a version that resolves this vulnerability.Patch master-763-4fcc6fe
Event History
Frequently Asked Questions
Who is exposed to this issue?
Users of stable-diffusion.cpp builds from master-742-1a13107 through master-763-4fcc6fe are exposed if they load an untrusted .imatrix file through the --imat-in conversion path. A model does not need to be loaded for the vulnerable path to be reached.
What does an attacker need to exploit it?
An attacker needs to induce a user or process to load a crafted .imatrix file. The file must contain duplicate tensor names, with a smaller nval in the first entry and a larger nval in a later entry using the same name.
What can be done before updating?
Do not load .imatrix files from untrusted sources through --imat-in. Restrict that conversion path to reviewed files until the build can be updated to master-763-4fcc6fe or later.
How can I determine whether a file is suspicious?
Inspect the .imatrix file for repeated tensor names whose later entry declares a larger nval than an earlier entry with the same name. Such a sequence triggers reuse of undersized values and counts buffers in the affected loader.