After the 27 November report of malicious GGUF models, check files statically: compute where tensor data ends, flag extra bytes, and diff the chat template.
What the 27 November report found
On 27 November 2026 the security project Malspark published a report on malicious GGUF models on Hugging Face. It says a scan of all 3,273,389 public model repositories on 26 November found five malicious GGUF models with 2,428 downloads as of 27 November, and notes that Hugging Face counts downloads, not people. The scan read GGUF headers and file ends through HTTP range requests and parsed 572,184 chat templates statically, without running any of them.
The report describes two campaigns. In one, a new account uploaded models whose GGUF files carried a Windows remote access program appended after the last tensor, and later rewrote the chat templates so the model would tell users to run a command that unpacks it. In the other, a template inserted a fake system directive, triggered by a phrase in the user's message, telling an agent with shell access to download and run a script. The report notes that neither technique is new on its own; what it documents is their use, and their combination, in models published on Hugging Face.
This guide does not reproduce any payload or command from the report. It explains the two hiding places in terms of the GGUF format, and gives a static check you can run before loading a file: compute where the tensor data must end, compare it with the file size, and compare the embedded chat template with the base model's. The companion example gguf_trailing_bytes_check implements the check with the Python standard library and is tested on synthetic files and on real model files.
Where a GGUF file should end
The GGUF specification, in docs/gguf.md of the ggml repository, lays a file out in this order:
- A header: the magic
GGUF, a version, the tensor count and the metadata key-value count. - The metadata key-value pairs, including
general.alignment(32 if absent) and, usually,tokenizer.chat_template. - The tensor infos: for each tensor, its name, dimensions, type and an offset relative to the start of the data section.
- Padding up to the next multiple of the alignment.
- The tensor data. Each tensor's offset is a multiple of the alignment, and the space between tensors is padded.
Every byte a loader needs is described by the header. The end of the meaningful data is therefore computable without reading the weights: the start of the data section plus the largest offset + size over all tensors, where a tensor's size is its element count divided by its type's block size, times the bytes per block. Bytes after that point are never read by a runtime, so nothing that loads or evaluates the model notices them. That is the property the appended payload relied on.
One subtlety matters for avoiding false alarms. Some writers pad after the last tensor too. Files written by the gguf-py GGUFWriter, version 0.19.0, end with padding to the alignment; a small three-tensor test file had 26 bytes after the last tensor's data. So the rule is: up to alignment - 1 trailing bytes is padding, and anything more is a finding.
The check
data_start = header_end + (align - header_end % align) % align
data_end = data_start + max(offset + nbytes for name, offset, nbytes in tensors)
trailing = file_size - data_end
if trailing < 0:
findings.append("file is shorter than its tensor table says (truncated download)")
elif trailing >= align:
findings.append(f"{trailing} bytes after the last tensor; at most {align - 1} bytes of padding are expected")The companion's gguf_check.py reads the header, metadata and tensor table, takes the bytes per block for each ggml type from ggml-common.h at the llama.cpp v1.1.0 tag, and prints the data range, the trailing byte count, a SHA-256 hash of the chat template and any findings. It never reads the tensor data and never runs the template. It exits with status 1 when there is a finding, so it can gate a model download in CI.
Tested on real files
The checker ran on four GGUF files from a local Ollama model store: all-minilm, qwen2.5 0.5b-instruct, qwen2.5 1.5b and llama3.2. They range from 45,949,216 to 2,019,377,376 bytes and hold 101 to 338 tensors. Each ended exactly at the computed end of its tensor data, with 0 trailing bytes and no findings.
The synthetic tests cover the other cases: a clean file with tail padding passes, a clean file without tail padding passes, a file with an appended block is flagged, a truncated file is flagged as shorter than its tensor table, and two files that differ only in their chat template have identical tensor ranges but different template hashes. A further test checks the type table against gguf-py's when that package is installed. Q8_1 is left out of the table on purpose: llama.cpp uses it as an intermediate type rather than as a file quantization target, and gguf-py 0.19.0 lists a different block size for it than ggml-common.h does at v1.1.0.
The template half
The chat template is a Jinja program stored under tokenizer.chat_template. The runtime renders it around every conversation to build the exact text the model sees, and most users never look at it. The Malspark report observes that C++ runtimes render templates in a restricted engine, so classic template-injection escapes do not apply there. The attacks it describes did not need them: ordinary template logic added hidden instructions to the conversation.
That makes the template a hidden system prompt written by whoever published the file. For a model that drives an agent with tools, it is part of your security boundary. The check is a comparison:
- Get the template the base model's publisher ships, from the original repository's
tokenizer_config.jsonorchat_template.jinja. - Compare it with the template embedded in the GGUF file, by hash for automation and by diff for review.
gguf_check.py FILE --template-ref base.jinjareports a finding if they differ. - Treat any difference as a code change that needs review. Fine-tunes legitimately change templates, but the change should be explainable: a new role token, a tool-call format. Text that addresses the model with instructions is not a format change.
- Pin the reviewed template. Several runtimes let you supply a template instead of using the embedded one, which removes the file's template from the trust path entirely.
A procedure for adopting a GGUF model
- Prefer files published by the model's original authors or by an organisation you already trust. Record the repository revision, not just the name, because a template can be rewritten in a later commit, as the report describes.
- Run the layout check and the template comparison before the first load, and again whenever you pull a new revision.
- Record the file's SHA-256 and the template hash in your model registry, and load only files that match.
- Run models that serve agents with the least privilege the task needs. A template can instruct the model; it cannot grant tools the runtime does not expose.
- Keep untrusted models away from shell or code-execution tools until they pass review.
Limits
The layout check finds bytes outside the region the header describes. It does not find data hidden inside tensors, such as in the low bits of weights (the 2021 EvilModel technique the report cites as prior work), or in the other hiding places the report demonstrates in a lab setting; those need different tools. The template comparison needs a trustworthy reference template, which may not exist for an original fine-tune. Neither check says anything about the model's behaviour. The report's own tool, gguf-radar, is published as open source; this guide's example is an independent, minimal implementation of the layout rule written for teaching and was not compared with it.
Verification
Run the companion tests, then run python gguf_check.py on the GGUF files you already use. A clean result has 0 or fewer than alignment trailing bytes and no findings. Add the template comparison for every model that can call tools, store the template hash next to the file hash, and fail the deployment when either changes without a review.