GGUF malware on Hugging Face: what hid after the last tensor, and how to check a model

A scan of 226,310 GGUF repositories on Hugging Face found five poisoned models from two accounts, downloaded 2,428 times. No loader exploit and no CVE: one trick hid instructions in the chat template, the other appended a Windows program after the last tensor, where no loader reads. A region-by-region tour of one GGUF file, and five checks before you run one.

On 26 November 2026, the security group Malspark scanned every public model repository on Hugging Face: 3,273,389 of them, including 226,310 GGUF repositories and 572,184 chat templates. Five GGUF repositories, from two accounts, were poisoned. By the next day they had 2,428 downloads (Malspark’s write-up, 27 November).

Two things in that sentence matter before anything else:

  • Downloads are not infections. Malspark says it plainly: “Hugging Face counts downloads, not people, so the number of affected users is lower or equal.” Nobody knows how many people actually ran the payload.
  • There was no exploit. No bug in llama.cpp, Ollama or LM Studio, no CVE. The two tricks used parts of the GGUF format exactly as designed.

This post walks through one GGUF file region by region, shows where each trick sat, and ends with five checks you can do before running a model you downloaded. Nothing was downloaded, loaded or tested for this post: every claim comes from the write-up, the format spec, the loaders’ source code and docs, all linked. On purpose, there’s no payload command here and no link to anything the attackers hosted.

The file, region by region

The GGUF spec describes a single file with four parts. For sizes, I use a clean, widely downloaded file: Llama 3.1 8B Instruct in Q4_K_M from bartowski’s repository (the same file our earlier GGUF explainer read the header of).

Region What it holds In the clean example
Header magic GGUF, version, tensor count, key–value count 24 bytes: version 3, 292 tensors, 33 pairs
Metadata typed key–value pairs: architecture, layers, tokenizer, chat template about 7.8 MB, template about 4.8 kB
Tensor table per tensor: name, shape, type, offset about 17 kB
Tensor data the weights, each tensor aligned to 32 bytes about 4.91 GB
After the last tensor nothing (in a clean file) 0 bytes
One GGUF file, region by region (not to scale), and where the two tricks satHeader24 bytesMetadatakey–value pairsTensor tablenames, offsetsTensor datathe weights, ~99.8%Appended bytespast the endwhat loaders read: the ranges the header and tensor table point tonever readTrick 1: tokenizer.chat_templatea Jinja program run on every message; it addedhidden instructions (“start every reply with onePowerShell line” / a fake directive for agents)Trick 2: a Windows program11.47 MB (about 10.25 MB of it Tor), appendedpast the end; the printed line cut it off thelargest .gguf in the user folder and started itToo short: llama.cpp stops (“data is not within the file bounds”). Too long: no check, no warning.safetensors: offsets must reach exactly the end of the file, or it refuses (“file not fully covered”).
Layout from the GGUF spec (ggml docs/gguf.md), which says nothing about bytes after the last tensor. Tricks and sizes from Malspark's write-up (27 Nov 2026). Loader checks read from llama.cpp src/llama-model-loader.h and safetensors src/tensor.rs on GitHub. Not to scale.

Metadata: the key that isn’t data

Most metadata is plain values: general.architecture = "llama", llama.block_count = 32, 128,256 tokenizer strings. One key is different. The spec defines tokenizer.chat_template as “a Jinja template that specifies the input format expected by the model”. It is a small program, and runtimes run it on every message to turn your chat into the exact text the model was trained on, special tokens included.

That’s normally boring. But a template can also add text: a system message you never typed and your chat window never shows. Researchers have warned about this for over a year. Pillar Security (July 2025) built a poisoned template that only triggered on HTML requests; when they reported it, Hugging Face “determined that this did not classify as a vulnerability”, and LM Studio said “users are responsible for reviewing and downloading trusted models”. A 2026 paper by Fogel et al. measured template backdoors across 18 models: with the trigger, factual accuracy fell from about 90% to 15% on average, with no measurable change on normal inputs, and the backdoors hijacked agent tool use while bypassing every injection defense they tested.

Trick 1: the template talks to the model

The two accounts used the template differently (as described by Malspark; paraphrased here):

  • Account A (repos dressed as “uncensored” builds) added a system message, in French, telling the model to begin every reply with one fixed PowerShell line, then answer normally. You ask about recursion; the answer opens with what looks like a setup command.
  • Account B (three identical copies of a small Qwen3 model presented as security models, plus an Ollama mirror) waited for the words “What is” in your message, then inserted a fake [SYSTEM DIRECTIVE] telling an agent with shell access to download a script and run it hidden. Malspark didn’t recover that second-stage script, so what it did is unknown. The directive was visible in Hugging Face’s own metadata viewer.

A bit of history explains why the attackers went this way. In May 2024, CVE-2024-34359 (CVSS 9.6) showed that llama-cpp-python rendered the GGUF template with a “sandbox-less jinja2.Environment”, so a template could run code directly; versions 0.2.30 to 0.2.71 were affected, 0.2.72 fixed it. Today’s runtimes render templates in a restricted engine, Malspark notes. So this time the template didn’t hack the software. It talked the model, or the agent, into handing the user a command.

Tensor table and data: where the model ends

Each tensor-table entry gives a tensor’s name, shape, type and offset from the start of the data region. That makes the end of the model computable. In the clean example, the data region starts at byte 7,840,928; the last tensor, output_norm.weight (4,096 F32 values, 16,384 bytes), sits at offset 4,912,881,920. Add them up and you get 4,920,739,232, which is exactly the file size Hugging Face reports for that file. To the byte.

Loaders memory-map the file and read only the ranges the table points to.

Trick 2: the bytes after the end

Account A’s files didn’t end there. After the last tensor came a Windows x64 program that unpacks to 11.47 MB, about 10.25 MB of which is a bundled Tor client; in the second model it was compressed with raw Deflate. Malspark: “Anything after that point is never read.”

The spec doesn’t say anything about bytes after the last tensor, and the loader doesn’t look. llama.cpp’s model loader throws “data is not within the file bounds, model is corrupted or incomplete” when a tensor would run past the end of the file. So a file that’s too short is an error. A file that’s too long gets no check and no warning.

safetensors made the opposite choice. Its README: “The byte buffer needs to be entirely indexed, and cannot contain holes. This prevents the creation of polyglot files.” In the code, if the offsets don’t reach exactly the end of the file, loading fails with MetadataIncompleteBuffer: “incomplete metadata, file not fully covered”. The same appended program would make a safetensors file refuse to load.

The two halves together

Neither half is an exploit, and the model answers normally. Together:

  1. the template makes the model print one line;
  2. the user runs it;
  3. the line finds the largest .gguf in the user’s profile and cuts the bytes off its end;
  4. and starts them.

According to Malspark’s analysis, what starts is a remote access trojan: it goes after saved browser passwords (newer Chrome “v20” entries stay undecrypted), crypto-wallet extensions, keystrokes, the clipboard, screenshots and the webcam, plus a Monero miner for when the machine is idle, all over Tor. One small mercy: its attempt to get admin rights through a UAC bypass fails, because of missing backslashes.

The week, day by day

Eight days in November 2026, one tick per day21222324252627282921–22: account B uploads 3 copies + an Ollama mirror; template armed22: account A creates 14 repos, 12 empty; model 1 has the program, clean template24: account A model 2 (program compressed), clean template26: account A adds the trigger, twice; scan: 1,502 downloads27: write-up published; 2,428 downloads; all 5 repos still online28: Hacker News front page (295 points)29: Hugging Face's public API lists no models for either accountDownloads made before the 26th carried account A's payload but no trigger in the template.
Sources: Malspark write-up (27 Nov 2026); Hacker News; Hugging Face public API queried 29 Nov 2026 (who removed the models is not stated anywhere we could find). Downloads are Hugging Face download counts, not people or confirmed infections.

The detail that changes the risk for early downloaders: account A uploaded the program first, with clean templates, and only swapped in the trigger on 26 November (twice, about nine hours apart). In Malspark’s words, “Downloads made before 26 November therefore contain the payload but not the trigger.” Account A also created 12 empty repositories named after models that hadn’t been released yet.

What I could check afterwards: on 29 November, Hugging Face’s public API listed no models under either account. I couldn’t find a statement from Hugging Face, so I can’t say who removed them.

How to check a GGUF before you run it

  1. Read the chat template. Hugging Face’s GGUF viewer shows metadata on the model page (docs). If you serve with llama.cpp, the server’s /props endpoint returns chat_template, “the model’s original Jinja2 prompt template”, and /apply-template shows the rendered prompt. Look for system text you didn’t expect, conditions on what the user typed, and anything that mentions commands, downloads or URLs.
  2. Override it with one you trust. llama.cpp’s server takes --chat-template-file (default: “template taken from model’s metadata”) (README). In Ollama, a Modelfile’s TEMPLATE sets “the full prompt template to be passed into the model”, and ollama show --modelfile shows the current one (docs). LM Studio takes the template from the file’s metadata by default but lets you edit it per model (docs). The original model’s template, from its own repository, is the safest choice.
  3. Do the size math. Data start plus the last tensor’s offset and size (rounded up to the alignment) should equal the file size. gguf-radar, the free MIT-licensed scanner Malspark released, does this and the template checks without running the model, can compare a template against the original model’s, and exits non-zero on SUSPICIOUS or MALICIOUS so it can gate a CI job.
  4. Prefer the model’s own organisation or a quantizer with a long history. The poisoned repos posed as “uncensored” and “security” builds, and as releases that didn’t exist yet.
  5. Don’t give agents an unrestricted shell, and treat model-suggested commands as untrusted. That’s Malspark’s first recommendation, and it defeats both tricks: the PowerShell line and the fake directive only work if someone, or something, runs them.

Five out of 226,310 is about one GGUF repository in 45,000. Rare. But both tricks cost the attackers almost nothing, neither needed a bug, and the format still doesn’t object to bytes after the end. Malspark asks hubs and runtimes to reject GGUF files with bytes after the last tensor or non-zero padding. Until that happens, the checks above are on you.

Sources