Black Friday: the complete AWS Security Bundle, 12 volumes, $99 $49.50 BLACKFRIDAY50 Grab it →
SecurityZines.com Join

GGUF Exploits

Malicious Model Files for llama.cpp

AI SecurityFlyer

GGUF Exploits (Malicious Model Files for llama.cpp): hand-drawn explainer poster

GGUF Exploits: how a malicious model file can take over the machine that loads it

Why GGUF is a risk: GGUF is the single-file model format used by llama.cpp and the tools built on it. Millions of people download quantized models from Hugging Face and similar hubs, and almost nobody audits the bytes. A .gguf file is a whole local LLM, but to the machine it is untrusted input handed to a parser written in C.

File anatomy: A GGUF file starts with the magic bytes and a version number. Then come the metadata key-value pairs (n_kv of them) with the model's parameters, then the tensor info section (n_tensors entries with names and dimensions), then the raw tensor data at an offset. Every count and size in there is chosen by whoever made the file.

How the loader parses it: The loader reads n_tensors and each tensor's dims, computes size = dims[0] x dims[1] x ..., calls malloc(size) and copies the raw weights in. If it does not check those numbers, it trusts every count it reads.

The integer overflow: The attacker forges the dimensions, for example dims = [2^32, 2^32]. The product is 264, which wraps to 0 in a 64-bit size_t. The loader allocates a tiny buffer, then copies gigabytes into it. That heap overflow can lead to remote code execution, and it fires just from loading the file, before you ever send a prompt. Several heap overflows of this shape were found and fixed in the GGUF loader in 2024.

Treat it as hostile: Keep llama.cpp (and Ollama, LM Studio, anything embedding it) updated to a patched build. Download from trusted publishers and verify the SHA256 hash. Run the loader with least privilege, ideally in a sandbox or container with no access to your secrets. Patch, verify, sandbox.

More on AI Security

All 15

Get the next one by email

New posters land in the Security Zines newsletter on Substack. Free, no spam.