Arviser

Loading a model file runs code: what happened, and how to test your loader

Facts

Failure class
KB-P-0001 · AI applications, Software supply chain
Record published
2018-06-27 · CVE-2017-18342 (PyYAML), the earliest dated record listed · source
Fix
2025-01-29 · PyTorch 2.6.0: torch.load defaults to weights_only=True · source
Fix
2026-01-21 · torch 2.10.0 uploaded to PyPI, the fixed version for CVE-2026-24747 · source
Record published
2026-07-19 · CVE-2026-12484 (Keras), the latest dated record listed · source
Our test run
2026-11-26 · Our lab run: torch 2.5.1, 2.6.0 and 2.10.0, NumPy 1.16.2 and 1.16.3, 5 runs per case
CVE
CVE-2017-18342, CVE-2019-6446, CVE-2023-6730, CVE-2024-3568, CVE-2024-3660, CVE-2024-34359, CVE-2024-37052, CVE-2024-11393, CVE-2025-24357, CVE-2025-1716, CVE-2025-1550, CVE-2025-32434, CVE-2025-8747, CVE-2025-10155, CVE-2025-9906, CVE-2025-9905, CVE-2025-49655, CVE-2025-62164, CVE-2026-22807, CVE-2026-24747, CVE-2026-1839, CVE-2026-1462, CVE-2026-4372, CVE-2026-12481, CVE-2026-12484
GitHub advisory
GHSA-rprw-h62v-c2w7, GHSA-9fq2-x9r6-wfmf, GHSA-3863-2447-669p, GHSA-37q5-v5qm-c9v8, GHSA-x4wf-678h-2pmq, GHSA-56xg-wfcc-g829, GHSA-76cg-cfhx-373f, GHSA-wrfc-pvp9-mr9g, GHSA-rh4j-5rhw-hr54, GHSA-655q-fx9r-782v, GHSA-48g7-3x6r-xfhp, GHSA-53q9-r3pm-6pq6, GHSA-c9rc-mg46-23w3, GHSA-jgw4-cr84-mqxg, GHSA-36fq-jgmw-4r9c, GHSA-36rr-ww3j-vrjv, GHSA-cvhh-q5g5-qprp, GHSA-mrw7-hf4f-83pf, GHSA-2pc9-4j83-qjmr, GHSA-63cw-57p8-fm3p, GHSA-69w3-r845-3855, GHSA-4f3f-g24h-fr8m, GHSA-29pf-2h5f-8g72, GHSA-5gwj-m78q-7pq3, GHSA-v2w2-w228-c444
CWE
CWE-502
MITRE ATLAS
AML.T0011.000, AML.T0010.003
OWASP Top 10 for LLM Applications
LLM03:2025
OWASP AI Testing Guide
AITG-INF-01
Class
Loading a model or config file runs code
OWASP note
LLM03:2025 Supply Chain names unverified pre-trained models, not pickle
AITG note
AITG-INF-01 Testing for Supply Chain Tampering is the nearest test. It does not mention model file formats
Lab
torch 2.5.1, 2.6.0 and 2.10.0; numpy 1.16.2 and 1.16.3; safetensors 0.4.5; picklescan 1.0.5. Last run 2026-11-26, 5 runs per case (results)
Next review
2027-05-27

Short answer: many model files are Python pickles, and loading a pickle can call any function the file names. torch.load did this by default until PyTorch 2.6.0, and np.load until NumPy 1.16.3 (CVE-2019-6446). The "safe" modes were bypassed too: CVE-2025-32434 and CVE-2026-24747 in PyTorch's weights_only=True, and Keras safe_mode repeatedly (CVE-2025-1550, CVE-2025-8747 and later). Test: load a canary through your real loader and check for a marker. Fix: safetensors, or explicit weights_only=True on torch 2.10.0 or later.

1. What goes wrong?

Short answer: a pickle file is a small program for rebuilding objects, and one of its instructions is "call this function with these arguments".

Python's own documentation puts it plainly: "The pickle module is not secure. Only unpickle data you trust", because "It is possible to construct malicious pickle data which will execute arbitrary code during unpickling." Hugging Face's page on pickle scanning names the opcodes involved: GLOBAL and STACK_GLOBAL import a name, REDUCE calls it. PyTorch checkpoints saved with torch.save hold their objects as a pickle inside a zip file: in strict mode our lab scanner reported the canary's import inside canary/data.pkl (raw output). The PyTorch security policy says "PyTorch models are programs" and that running untrusted models "is equivalent to running untrusted code". TensorFlow's policy opens with a matching heading, "TensorFlow models are programs".

Our illustration, not a quote: a checkpoint is a dictionary of tensors. Add one extra entry whose pickle instructions say open("/tmp/marker", "w"). A loader that runs REDUCE for any function creates the marker while it is still "reading weights". The marker is our harmless stand-in for whatever a hostile file would call instead.

The class is wider than pickle. Keras models could carry Lambda-layer code (CERT VU#253266, CVE-2024-3660) or configs that name functions to call (CVE-2025-1550). YAML loaders could build arbitrary objects (CVE-2017-18342). A GGUF file's chat template was rendered by llama-cpp-python as a Jinja2 template in a "sandbox-less" environment (CVE-2024-34359). In 2026, model configs that point a loader at more code appear in transformers (CVE-2026-4372) and vLLM (CVE-2026-22807). In each case a file that looks like data reaches an interpreter.

2. How did the pattern show up over the years?

Short answer: the same mistake moved from data libraries to model hubs and serving stacks, then to the "safe" loaders and the scanners meant to stop it, and it was still producing records in 2026.

Dates are record or post dates from the primary source, with their precision. Each case links to its record.

Date (precision) Kind Case Package or service What was new that time
2018-06-27 (day) CVE record published CVE-2017-18342 PyYAML before 5.1 yaml.load() "could execute arbitrary code if used with untrusted data". Config files, the same mistake
2019-01-16 (day) CVE record published, disputed CVE-2019-6446 NumPy before 1.16.3 np.load unpickled object arrays by default. The record carries a third-party dispute: loading pickled arrays "might have legitimate applications"
2021-03-15 (day) Researcher post "Never a dill moment", Trail of Bits Pickle-based model formats "Many machine learning (ML) models are Python pickle files under the hood." Released the Fickling tool
2023-05-23 (day) Audit post safetensors audit by Trail of Bits, for Hugging Face, EleutherAI and Stability AI safetensors A format with no object rebuilding. "No critical security flaw leading to arbitrary code execution was found"
2023-12-19 (day) CVE record published CVE-2023-6730 transformers before 4.36.0 A library helper that unpickles
2024-02-27 (day) Researcher post JFrog, malicious models on Hugging Face Hub users of torch.load "around 100 instances of such models". Example baller423/goober2, later deleted
2024-04-10 (day) CVE record published CVE-2024-3568 transformers before 4.38.0 pickle.load() in a TensorFlow checkpoint helper. GitHub rates it low
2024-04-16 (day) CVE record published CVE-2024-3660 Keras before 2.13 Lambda layers in saved models run code, per CERT VU#253266. GitHub lists 2.13.1rc0 as the first patched version
2024-05-10 (day) CVE record published CVE-2024-34359 llama-cpp-python 0.2.30 to 0.2.71 Model metadata rendered as a Jinja2 template. Fixed in 0.2.72, uploaded to PyPI the same day
2024-06-04 (day) CVE record published CVE-2024-37052 MLflow 1.1.0 and later A "maliciously uploaded scikit-learn model". GitHub lists no patched version
2024-11-04 (day) Vendor forum post PyTorch announces the weights_only flip torch nightlies, 2.6 and later The default changes after years of the unsafe default
2024-11-22 (day) CVE record published CVE-2024-11393 (ZDI) transformers before 4.48.0, MaskFormer One more model class that unpickles
2025-01-27 (day) CVE record published, fix the same day CVE-2025-24357 vLLM before 0.7.0 A serving stack calling torch.load on hub downloads with the old default
2025-01-29 (day) Release PyTorch 2.6.0 torch torch.load defaults to weights_only=True
2025-02-06 (day) Researcher post ReversingLabs, "nullifAI" Hugging Face scanning Two models in 7z archives "were not flagged as 'unsafe'". Removed "in less than 24 hours"
2025-02-26 (day) CVE record published CVE-2025-1716 picklescan The scanner did not treat pip as unsafe. Fixed in 0.0.21 per the CVE record and the 0.0.21 source; GitHub's advisory lists 0.0.22
2025-03-11 (day) CVE record published CVE-2025-1550 Keras 3 Code execution "even with safe_mode=True". The CVE record says before 3.8.0, GitHub says before 3.9.0
2025-04-18 (day) CVE record published CVE-2025-32434 torch 2.5.1 and earlier RCE "when loading a model using torch.load with weights_only=True". Fixed in 2.6.0, which shipped before the record
2025-08-11 (day) CVE record published CVE-2025-8747 Keras 3.0.0 to 3.10.0 A safe_mode bypass of the CVE-2025-1550 fix. Fixed in 3.11.0
2025-09-17 (day) CVE record published CVE-2025-10155 picklescan up to 0.0.30 A pickle with a PyTorch file extension was "incorrectly considered safe". Fixed in 0.0.31
2025-09-19 (day) CVE records published CVE-2025-9906, CVE-2025-9905 Keras before 3.11.0 and before 3.11.3 Two more paths to code execution "even with safe_mode=True"
2025-10-17 (day) CVE record published CVE-2025-49655 Keras 3.11.0 to before 3.11.3 Code runs "despite safe mode being enabled"
2025-11-21 (day) CVE record published CVE-2025-62164 vLLM 0.10.2 to before 0.11.1 torch.load() of user-supplied prompt embeddings; memory corruption that could "potentially lead to code execution"
2026-01-21 (day) CVE record published CVE-2026-22807 vLLM 0.10.1 to before 0.14.0 Code from a model repository's auto_map loaded "without gating on trust_remote_code"
2026-01-27 (day) CVE record published CVE-2026-24747 torch before 2.10.0 A second weights_only=True bypass: a crafted checkpoint "can corrupt memory and potentially lead to arbitrary code execution". Fixed in 2.10.0
2026-04-07 (day) CVE record published CVE-2026-1839 transformers before 5.0.0rc3 The Trainer calls torch.load() "without the weights_only=True parameter" on a checkpoint file. The record limits the impact to "PyTorch versions below 2.6"
2026-04-13 (day) CVE record published CVE-2026-1462 Keras before 3.13.2 TFSMLayer loads attacker-controlled SavedModels "even when safe_mode=True"
2026-05-24 (day) CVE record published CVE-2026-4372 transformers before 5.3.0 A crafted config.json field leads to remote code execution on a standard load
2026-07-03 (day) CVE record published CVE-2026-12481 Keras before 3.12.3, and 3.13.0 to before 3.15.0 "Lambda deserialization can bypass safe mode and execute code"
2026-07-19 (day) CVE record published CVE-2026-12484 Keras TorchModuleWrapper calls torch.load(..., weights_only=False). The CVE record names 3.15.0 as affected; GitHub lists 3.15.0 as the patched version

The table holds the records we opened on 2026-11-26. The GitHub Advisory Database lists far more picklescan records than these two (counted in section 3).

3. Why does it keep coming back?

Short answer, our view: the unsafe behavior was the convenient default, it sits inside libraries you do not read, and the fixes that came first were lists that kept being bypassed.

The default was the risk. torch.load(path) with no arguments ran arbitrary pickle code until 2.6.0. The 2.6.0 release notes call the flip the end of "the deprecation that started in 2.4". Code written before 2025, tutorials and copied snippets still carry the one-liner, and their behavior depends on the installed torch. In our lab the same function ran our canary on 2.5.1 and refused it on 2.6.0 with no code change. Pinning an old torch for an unrelated reason brings the old behavior back, with at most a FutureWarning in the logs, as our 2.5.1 runs printed.

The loader is often not in your code. CVE-2025-24357 was a torch.load inside vLLM's weight iterator. CVE-2023-6730, CVE-2024-3568, CVE-2024-11393 and CVE-2026-1839 (with torch below 2.6, per the record) were inside transformers. A team can grep its own repository and find no torch.load, while a dependency calls it on every hub download.

The first fixes were lists, and they were bypassed. weights_only=True is an allowlist of functions. It was bypassed in torch 2.5.1 and earlier (CVE-2025-32434; the fix commit linked from the advisory is titled "Prevent legacy_load when weights_only=True") and again before 2.10.0 (CVE-2026-24747).

Keras safe_mode had at least five bypass records in 2025 (CVE-2025-1550, CVE-2025-8747, CVE-2025-9906, CVE-2025-9905, CVE-2025-49655) and more in 2026 (GitHub advisories for keras).

Scanners decide by the names of imported functions. GitHub lists 52 picklescan advisories published in 2025 and 7 in 2026, not counting those marked as duplicates, and most of their titles describe a missed detection or a bypass (GitHub advisories for picklescan; our count from the API on 2026-11-26). None of them lists 1.0.5, the current release, as affected. ReversingLabs found files the Hub's scanning did not flag (post).

picklescan documents exit code 1 as "scan found malware", and in its default mode a "suspicious" global does not count. In default mode picklescan 1.0.5 counted one suspicious global in our canary (--globals names it as _io.open) and exited with code 0. A pipeline that gates only on the default exit code passes such a file. With --strict, which the tool describes as "default-deny mode", it exited 1 (raw output). This is one canary and one version's documented default mode, not a verdict on the tool.

Model files are more than weights. Configs, Lambda layers and chat templates travel with the weights, and the 2026 records for transformers (CVE-2026-4372) and vLLM (CVE-2026-22807) are about configs that bring in code. Switching the tensor format does not cover a template or a config that the runtime interprets.

4. How do you test your own loader in five minutes?

Short answer: create a canary file, load it through the exact function your service uses, and fail the test if a marker file appears. The script first proves that your function really loads a plain file of the same format.

Test ID KB-T-0001 (proposed). The script is check_loader.py in the lab (third version). It needs Python 3.8 or later and the standard library, plus torch or numpy for those formats.

# in a throwaway container or virtualenv with no secrets
python check_loader.py your_package.models:load_checkpoint --format pt
python check_loader.py your_package.embeddings:load_vectors --format npy

The script writes a control file (plain data) and a canary file (the same data plus one object that creates a marker) into a new temporary folder. It calls your function on the control file and then once on the canary, each time in a new Python process that waits 2 seconds after the call (--wait), and watches Python's open() calls with an audit hook. The new process per call catches a loader that caches one model per process. The wait catches a loader that unpickles in a background thread shortly after it returns. The lab has one example of each, and both give FAIL.

Exit code Result Meaning
0 PASS The control file loaded and was opened, the canary was opened, and no marker appeared after the wait
1 FAIL The marker appeared: your loader ran a function chosen by the file
2 SETUP ERROR Bad arguments, your loader could not be imported, the format's library is missing, no usable temporary folder, Python older than 3.8, or any other error of the script itself. Exit code 1 means only FAIL
3 INCONCLUSIVE Your loader failed on the plain control file, or never opened the control or the canary

Three quick checks to run next to it:

pip show torch numpy keras transformers vllm 2>/dev/null | grep -E '^(Name|Version)'
grep -rnE 'torch\.load|pickle\.loads?|np\.load|joblib\.load|cloudpickle|yaml\.load|weights_only=False|allow_pickle=True|pickle_module=' --include='*.py' .
env | grep -E 'TORCH_FORCE_(NO_)?WEIGHTS_ONLY_LOAD'

The last line matters because torch reads TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD. In the 2.6.0 source, when it is set to 1, y, yes or true and the call does not pass weights_only, torch loads with weights_only=False. The same source also turns the safe default off when a call passes its own pickle_module, which is why the grep looks for it. Our lab confirmed the variable on 2.6.0 and on 2.10.0: the canary ran in 5 of 5 runs on each with the variable set to 1 (results).

5. What did we run?

Short answer: 125 loads in fresh containers with no network, 175 runs of the reader's test across three versions of the script (20, 70 and 85 runs; the table shows the third) and 60 scans, all on 2026-11-26. Every case with a recorded expectation matched it. We did not reproduce any bypass.

Lab record, run on 2026-11-26 by the drafting agent (Claude Opus 5.5) on a Linux workstation, Docker 29.10.0. Reviewer of the record: a separate AI checking agent, three rounds. The first two rounds found errors that this version fixes; the third found none that block publication. Raw files: model-file-loading/results/2026-11-26/.

Case torch 2.5.1+cpu torch 2.6.0+cpu torch 2.10.0+cpu
torch.load(path), canary marker in 5 of 5 refused (UnpicklingError) 5 of 5, no marker refused 5 of 5, no marker
torch.load(path, weights_only=True), canary refused 5 of 5 refused 5 of 5 refused 5 of 5
torch.load(path, weights_only=False), canary marker in 5 of 5 marker in 5 of 5 marker in 5 of 5
torch.load(path) with TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD=1, canary not run marker in 5 of 5 marker in 5 of 5
torch.load(path), plain tensors loaded 5 of 5 loaded 5 of 5 loaded 5 of 5
safetensors 0.4.5 load_file, plain tensors loaded 5 of 5 loaded 5 of 5 loaded 5 of 5
Reader's test on torch.load(path, map_location="cpu") FAIL 5 of 5 PASS 5 of 5 PASS 5 of 5
Reader's test on the same with weights_only=True PASS 5 of 5 PASS 5 of 5 PASS 5 of 5

The refusals on 2.6.0 and 2.10.0 show the default for this canary. They do not show that 2.6.0 is safe: it is inside the affected range of CVE-2026-24747, which our canary does not test.

Case numpy 1.16.2 numpy 1.16.3
np.load(path), object array canary marker in 5 of 5 refused (ValueError) 5 of 5, no marker
np.load(path, allow_pickle=False) refused 5 of 5 refused 5 of 5
np.load(path, allow_pickle=True) marker in 5 of 5 marker in 5 of 5
np.load(path), plain array loaded 5 of 5 loaded 5 of 5

Checks of the reader's test itself (third version, torch 2.6.0 image unless noted, 5 runs each, results): plain pickle.load on a pickle canary gave FAIL. Two loaders that run pickle code also gave FAIL: one that caches a single model per process, and one that unpickles in a background thread half a second after it returns. The second version of the script had reported PASS for both shapes, as the independent check found, which is why each call now runs in a new process with a wait. A loader that never reads the file, one that raises FileNotFoundError before reading, and a safetensors loader given a .pt file each gave INCONCLUSIVE. A missing module, an argument without :, no writable temporary folder, a missing torch (scanner image) and Python 3.7 (numpy 1.16.2 image) each gave SETUP ERROR. All 85 runs matched the expected result written into the script before the run.

picklescan 1.0.5, scan only Default mode --strict
canary.pt exit 0, "Suspicious globals: 1", "Dangerous globals: 0" (5 of 5) exit 1, "Infected files: 1" (5 of 5)
canary.npy exit 0, "Suspicious globals: 2" (5 of 5) exit 1, "Infected files: 1" (5 of 5)
benign.pt, benign.npy exit 0, nothing found (5 of 5) exit 0, nothing found (5 of 5)

On 2.6.0 the refusal message names the function it blocked ("Unsupported global: GLOBAL _io.open was not an allowed global by default") and tells the user that rerunning with weights_only=False "can result in arbitrary code execution" (message). On 2.5.1 the default load printed a FutureWarning about the coming change and loaded the file.

Setup. Each load ran in a new container with --network none, a read-only root filesystem, a 16 MB /tmp (one test case ran without it on purpose), all capabilities dropped, no-new-privileges, a non-root user and no privileged mode. The only host folders mounted were the lab's own files/ and files-2.10/ (read-only during loads, written once by a container running as the host user) and, for one test case, the lab's own src/ (read-only). No run started with a marker already present.

Versions. Base images python:3.12-slim@sha256:191083cd…51b4b (Python 3.12.16) and python:3.7-slim@sha256:b53f496c…f028b (Python 3.7.17, because numpy 1.16 has no wheels for current Python). torch wheels from the PyTorch CPU index, sha256 4856f9d6…4840 (2.5.1+cpu) and 59e78aa0…4d91 (2.6.0+cpu); the 2.10.0+cpu hash is in the package list. The images were built three times on 2026-11-26. The wheel hash lists of the first and third builds are equal for every image (comparison). The second build recorded only that its lists matched, and the lists themselves were not kept. run_torch_2_10.sh writes its own test files with torch 2.10.0 and records their hashes (files). Image IDs are local builds, not registry digests.

What these runs showed. The two default changes behave as their release notes say, and 2.10.0 keeps the safe default. An explicit flag overrides the default in both directions on every version we ran. One environment variable restores the old torch default on 2.6.0 and 2.10.0. picklescan's default exit code ignores its "suspicious" category, as its exit-code list and CLI code show.

What they did not show. We did not test CVE-2025-32434, CVE-2026-24747, the Keras safe_mode bypasses, the picklescan bypasses or the files from the JFrog and ReversingLabs posts. We did not run vLLM, transformers, Keras, MLflow or llama-cpp-python. We used one payload shape. The runs say nothing about GPU builds or other operating systems.

Expectations. For the first 95 loads we took the expected result of each case from the release notes and documentation and typed the table after a one-run smoke test of the same cases, before the five recorded runs. The output of that first smoke run was not kept. For the torch 2.10.0 runs and the second and third versions of the reader's test, the expectations were written to files before the runs. The smoke runs of both test versions are kept, the second with a note on one row that matched for the wrong reason. The scanner runs had no recorded expectation.

6. Which fixes hold, and which do not hold alone?

Short answer: prefer a format that cannot carry code. Where you must use pickle, pass the strict flag on a version with no open advisory. Treat scanner output as a hint, and load anything you did not produce in a sandbox.

7. Questions for your team

  1. Which function in our code, or in our dependencies, loads weights we did not produce, and what does check_loader.py print for it?
  2. Which torch, numpy, keras and transformers versions run in production images, not only in the lockfile, and do any of them have an open advisory?
  3. Is TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD set anywhere, for example in a container build file someone edited to silence an error?
  4. Do we convert hub checkpoints to safetensors before they reach a service with credentials?
  5. If we scan model files, does the pipeline fail on a "suspicious" finding, or only on the default exit code?

Sources

Primary records first. Record identifiers link from the facts box.

Records and release notes

Vendor documentation and statements

Researchers

Taxonomies

Our lab

Corrections

No corrections.

Report an error to contact@arviser.com.

How this page was made: Claude Opus 5.5, an AI model, built the lab and wrote this page from the sources listed. A separate AI agent rechecked the claims in three rounds. Vadim Nareyko set the scope and the publishing rules.

Text and data on this page: CC BY 4.0. Code in our lab: MIT. Quoted third-party material keeps its own terms.

Request a security review