Repository navigation
Description
Summary
This repository vendors a copy of ultralytics (8.0.120) at ultralytics/nn/autobackend.py, and its model-loading code evaluates ONNX metadata strings with eval(): AutoBackend.__init__ reads the model file's own custom_metadata_map and passes the imgsz / names / kpt_shape values through eval(). The evaluation happens while the model is being loaded — before any inference — so a hostile .onnx file executes arbitrary Python code in the loading process. The upstream ultralytics project replaced this eval() with ast.literal_eval() in release v8.3.234 (PR [#22847](ultralytics/ultralytics#22847), commit 265b92fa); the copy vendored here predates that release and still contains the vulnerable line.
Why this repository is affected
- Vendored copy:
ultralytics8.0.120, atultralytics/nn/autobackend.py - Current default branch:
b4ed20c2fed75eadc5aa7d8b09fedd137b873b52(re-checked 2026-09-29, unchanged) — still contains the vulnerable code - Metadata read (source):
ultralytics/nn/autobackend.py:132—session.get_modelmeta().custom_metadata_map - Sink:
ultralytics/nn/autobackend.py:278—metadata[k] = eval(v)forkin{"imgsz", "names", "kpt_shape"} - Vendoring profile: The vendored tree is nearly stock 8.0.120: a git blob-SHA comparison against upstream tag v8.0.120 (2026-09-24) shows 159 of 161 package files byte-identical, 1 file modified (
yolo/utils/ops.py).nn/autobackend.py— the file containing the sink — is byte-identical to upstream v8.0.120, so the upstream one-line fix applies verbatim.
Details common to all vendored copies:
metadata_propsis an arbitrary string-to-string map inside the.onnxprotobuf. Rewriting it needs no signing key, does not disturb the graph or the weights, and the file loads and infers normally.- There is no validation of any kind between the read and the sink — no allowlist, no regex, no sandbox;
evalruns with unrestricted builtins, so__import__is usable. - The key set is not a mitigation (it selects which values are evaluated; the values themselves are never inspected), and
check_class_names()runs only after the sink, so it cannot un-run the evaluation. - Nothing on the path is opt-in: the sink is inside
AutoBackend.__init__, before any inference call, with no flag or trust decision. - The same file already uses
ast.literal_evalfor its TFLite metadata branch — which is why the upstream fix is a one-line change. - A second channel reaches the same loop: an external
metadata.yamlsidecar next to the weights (yaml_loaditself usesyaml.safe_load, but the strings it produces still reacheval()).
How it was verified
Code-level verification at this repository's default branch: the source and sink lines were re-read live at HEAD on 2026-09-29. Execution-level (2026-09-29): the exact bytes this repository vendors were executed — the official PyPI ultralytics 8.0.120 wheel, whose nn/autobackend.py is byte-identical to this repository's vendored file (same sha256 55a5363f…), was driven through AutoBackend(weights=…) with a harmless sentinel expression in the metadata (it only writes one inert marker file) and a benign-metadata negative control: the marker appears for the attack artifact, never for the control. A sibling vendored copy of the same lineage (iMoonLab/yolov13, 8.3.63) was additionally driven end-to-end through the product's own yolo predict CLI. This repository vendors ultralytics 8.0.120, several hundred lines adrift from current upstream.
No exploit string is included in this issue. The verification used deliberately harmless sentinel expressions, with no network, no shell and no persistence.
Recommended fix
Sync the vendored copy to ultralytics >= 8.3.234 (preferred), or cherry-pick the upstream one-liner into ultralytics/nn/autobackend.py:
- metadata[k] = eval(v)
+ metadata[k] = ast.literal_eval(v)ast is already imported in this file, and ast.literal_eval is already used a few dozen lines above for the TFLite branch. Optional hardening beyond the upstream one-liner: wrap the parse in try/except and fall back to built-in defaults; validate the parsed structure (imgsz/kpt_shape as positive ints, names as a dict of int to str); apply the same handling to the external-YAML branch.
Activity