CVE-2026-43627 in llama.cpp
Summary
by MITRE • 08/07/2026
llama.cpp builds b1283 through b9058 contain an integer overflow vulnerability in the llama_batch_init() function where unchecked multiplications in malloc() calls can wrap past INT32_MAX when computing allocation sizes. Attackers can pass specially crafted parameters to trigger integer overflow, causing heap corruption and potentially achieving arbitrary code execution through subsequent batch operations that write past allocated buffer boundaries.
If you want to get the best quality for vulnerability data then you always have to consider VulDB.
Analysis
by VulDB Data Team • 08/07/2026
The vulnerability exists within the llama.cpp library version range b1283 through b9058 where the llama_batch_init() function contains a critical integer overflow flaw that can lead to heap corruption and potential arbitrary code execution. This issue stems from unchecked multiplications in malloc() calls that occur during buffer size calculations, specifically when computing allocation sizes for batch operations. The vulnerability manifests when attackers provide specially crafted parameters that cause arithmetic operations to wrap past the 32-bit signed integer maximum value of 2147483647, resulting in unexpectedly small allocation sizes that subsequently enable memory corruption.
The technical implementation of this flaw involves the multiplication of multiple user-supplied parameters without proper overflow checking before passing these values to malloc() functions. When these multiplications exceed INT32_MAX, they wrap around to negative or much smaller positive values due to integer arithmetic behavior on 32-bit systems. This produces allocations that are significantly smaller than required for legitimate batch processing operations, creating buffer overflows when subsequent code attempts to write data beyond the allocated memory boundaries. The flaw directly aligns with CWE-190, which addresses integer overflow conditions that can lead to buffer overflows and memory corruption.
The operational impact of this vulnerability extends beyond simple memory corruption to potentially enable remote code execution in contexts where the library is used for processing untrusted input data. Attackers can leverage this vulnerability by crafting malicious batch parameters that trigger the overflow condition during initialization, leading to heap corruption that may be exploitable through subsequent write operations within the batch processing pipeline. The risk is particularly elevated when llama.cpp is integrated into applications that process external data feeds or user-provided content without proper input validation.
Mitigation strategies should focus on implementing robust integer overflow checking before any memory allocation operations within the llama_batch_init() function and related batch processing routines. Developers should employ bounds checking mechanisms to validate multiplication results against maximum allowable values, ensuring that computed buffer sizes remain within safe operational limits. Input parameter validation becomes critical in preventing exploitation, requiring verification that all batch initialization parameters fall within expected ranges. Additionally, implementing proper error handling for allocation failures and employing address sanitizers or memory protection mechanisms can help detect and prevent exploitation attempts, aligning with defensive programming practices recommended by the software security community.
The vulnerability demonstrates characteristics consistent with ATT&CK technique T1203, which involves exploitation of input validation flaws to achieve arbitrary code execution through memory corruption. The integer overflow represents a classic example of how seemingly benign parameter processing can create security vulnerabilities that enable sophisticated attack vectors. Organizations using llama.cpp should prioritize immediate patching of affected versions and implement runtime monitoring to detect potential exploitation attempts targeting this specific vulnerability pattern within their deployed systems.