CVE-2026-47747: stable-diffusion.cpp Heap Buffer Overflow in .ckpt Parser
stable-diffusion.cpp, a C/C++ library for running inference on diffusion models like Stable Diffusion and Flux, contains a memory safety flaw in its checkpoint file parser. When processing .ckpt model files, a sign-confusion bug in the BINUNICODE opcode handler causes the parser to interpret a negative length value as an extremely large positive number, triggering an out-of-bounds memory copy that corrupts the heap. An attacker who controls a .ckpt file can exploit this to crash applications or potentially execute arbitrary code. The vulnerability affects versions prior to master-584-0a7ae07.
Source data · NVD / CISA · public domain
- CVSS
- 3.1 · 7.8 HIGH · CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
- Weaknesses (CWE)
- CWE-122, CWE-787
- Affected products
- 1 configuration(s)
- Published / Modified
- 2026-06-16 / 2026-06-25
NVD description (verbatim)
stable-diffusion.cpp is a pure C/C++ library for running diffusion model (Stable Diffusion, Flux, Wan, Qwen Image, Z-Image, and more) inference. In versions prior to master-584-0a7ae07, the pickle .ckpt parser in src/model.cpp contained a heap buffer overflow vulnerability in the BINUNICODE opcode handler. The issue was caused by sign confusion on the opcode length field. A crafted .ckpt file could trigger memcpy with a very large length derived from a negative signed value, causing immediate heap corruption. The issue has been resolved in version master-584-0a7ae07. If developers are unable to immediately update their applications they can work around this issue by only loading .ckpt checkpoint files from trusted sources and preferring trusted model sources and safer formats such as .safetensors where possible.
4 reference(s) · View on NVD →
SEC.co analysis · AI-assisted, reviewed against source
Technical summary
The vulnerability exists in src/model.cpp's pickle opcode parser, specifically in the BINUNICODE handler used to deserialize .ckpt checkpoint files. The root cause is a sign-confusion error on the opcode length field: a signed integer is cast or used in a context expecting an unsigned value. When a negative length is interpreted as unsigned, memcpy receives a very large size parameter, writing beyond allocated heap boundaries. This violates CWE-787 (out-of-bounds write) and CWE-122 (heap-based buffer overflow). The condition requires user interaction (loading a crafted .ckpt file) and local access, but no special privileges are needed.
Business impact
Organizations embedding stable-diffusion.cpp in AI/ML applications face denial-of-service risk if they load untrusted model checkpoint files—a common occurrence in open-model-sharing scenarios. Heap corruption can cause unpredictable crashes, degrading service availability. In worst-case scenarios, exploitation could enable code execution within the process context, potentially compromising the host system if the application runs with elevated privileges or processes sensitive data. Teams relying on community-sourced or third-party checkpoints without validation are at elevated risk.
Affected systems
Any application or service using leejet/stable-diffusion.cpp versions prior to master-584-0a7ae07 and loading .ckpt checkpoint files is affected. This includes AI inference services, machine-learning pipelines, and tools that allow users to supply custom model files. The vulnerability does not affect .safetensors or other non-pickle-based model formats.
Exploitability
Exploitation requires an attacker to craft a malicious .ckpt file and trick or convince a user to load it into an application using the vulnerable library. There is no remote attack vector; the vulnerability is local and requires user interaction. The low barrier to crafting a malicious .ckpt file (modifying the opcode length field) and the prevalence of model-sharing practices make exploitation feasible in open-ecosystem environments. Public exploit code has not been reported.
Remediation
Update stable-diffusion.cpp to version master-584-0a7ae07 or later. If immediate updating is not feasible, restrict .ckpt file loading to trusted, internally controlled sources and encourage migration to safer formats like .safetensors. Implement file validation or sandboxing if loading user-supplied checkpoints is unavoidable. Code review of pickle deserialization in custom integrations is recommended.
Patch guidance
Upgrade to master-584-0a7ae07 or the latest stable release of leejet/stable-diffusion.cpp from the project's repository. Verify the commit hash in your build environment. If using a stable release tag, check the project's release notes to confirm the fix is included. Test model inference with your existing .ckpt files before full production rollout to ensure compatibility.
Detection guidance
Monitor for unexpected heap-corruption or segmentation-fault crashes when loading .ckpt files, particularly from external sources. In debug builds, heap sanitizers (e.g., AddressSanitizer) will immediately flag the overflow. Audit application logs for failures during model initialization. If you control model distribution, validate checkpoint files before deployment and prefer distributing models in .safetensors format. Network-level detection is not applicable since the exploit is file-based.
Why prioritize this
This vulnerability merits prompt remediation due to its HIGH CVSS score (7.8), the ease of crafting a malicious payload, and the prevalence of model-sharing in AI/ML workflows. While exploitation requires local access and user interaction, the potential for code execution and the minimal attack preparation effort elevate the risk. Organizations with open model-loading pipelines should prioritize patching.
Risk score, explained
The CVSS 3.1 score of 7.8 (HIGH) reflects: local attack vector (low scope but no remote exposure); low attack complexity (straightforward opcode manipulation); no privilege elevation required; user interaction needed (model loading); and high impact (heap corruption enables confidentiality, integrity, and availability violations). The score appropriately captures the severity of heap overflow in a widely-used ML library, despite the local-access requirement.
Frequently asked questions
Can this vulnerability be exploited remotely?
No. The vulnerability requires local access and user interaction—specifically, the loading of a crafted .ckpt file into an application using the vulnerable library. There is no network-based attack vector.
Are .safetensors files affected?
No. The vulnerability is specific to the pickle-based .ckpt format parser. Applications using .safetensors or other model formats are not affected.
What should we do if we cannot update immediately?
Restrict checkpoint file loading to trusted, internal sources and audit the origins of any .ckpt files in use. Consider migrating model distribution to .safetensors format. Implement file integrity checks if feasible, and monitor for unexpected crashes or failures during model initialization.
Is there a public exploit?
There is no publicly disclosed exploit code for this vulnerability. However, crafting a malicious .ckpt file is feasible for an attacker with knowledge of the pickle format and the sign-confusion bug.
This analysis is provided for informational purposes to support vulnerability management and risk assessment. It is not a substitute for vendor advisories or independent security testing. Organizations should verify all technical details and patch applicability against official vendor documentation. SEC.co does not guarantee the accuracy of third-party source data and recommends cross-referencing with authoritative security databases and vendor releases. No exploit code or weaponized proof-of-concept is provided herein. Source: NVD (public-domain), retrieved 2026-07-24. Analysis generated by SEC.co (claude-haiku-4-5).
Related vulnerabilities
- CVE-2026-47749HIGHHeap Buffer Overflow in stable-diffusion.cpp Checkpoint Parser
- CVE-2026-0149HIGHAndroid RTP Heap Buffer Overflow Leading to Remote Code Execution
- CVE-2026-44421HIGHFreeRDP Heap Buffer Overflow in RDPGFX (CVSS 8.8)
- CVE-2026-46520HIGHImageMagick Out-of-Bounds Heap Write Denial of Service
- CVE-2026-53465MEDIUMImageMagick Heap Buffer Overflow in SF3 Encoder
- CVE-2026-47750HIGHHeap Buffer Overflow in stable-diffusion.cpp .ckpt Parser
- CVE-2021-4478HIGHDräger CC-Vision Buffer Overflow in .gdt File Parsing
- CVE-2023-43688HIGHMalwarebytes Heap Buffer Overflow Denial of Service Vulnerability