ONNX Runtime ConstantOfShape Constant-Folding Load DoS
Defensive validation / triage only. This repository contains a harmless reproduction artifact for bounded local load-time memory amplification.
A tiny crafted ONNX model can force ONNX Runtime's default L1 constant-folding pass to eagerly materialize a huge ConstantOfShape result during normal session creation. In current testing, an 85-byte model expands into roughly 582 MB peak RSS on onnxruntime 1.26.0 and 1.27.0 before any inference occurs.
Files
model/onnx-constantofshape-load-dos.onnx: crafted 85-byte artifactmodel/small-control.onnx: 81-byte control artifactgenerator/build_constantofshape_constant_folding_load_dos.py: deterministic internal builderreproduce/replay_constantofshape_constant_folding_load_dos.py: isolated replay harness with JSON outputbuild-meta.json: pinned measurements and artifact metadata
Differential
- Control:
81bytes on disk, output shape[1024] - Crafted:
85bytes on disk, output shape[134217728] - Observed on Ubuntu 24.04 x86_64:
onnxruntime 1.26.0: crafted default load peaks around581 MBRSSonnxruntime 1.27.0: crafted default load peaks around582 MBRSSonnxruntime 1.27.0withORT_DISABLE_ALL: same artifact stays around57 MBRSS
Quick Repro
/home/chopp3r/mfv-hunts/onnx_20260717/.venv/bin/python \
/home/chopp3r/mfv-hunts/onnx_20260717/poc/onnxruntime-constantofshape-constant-folding-load-dos/reproduce/replay_constantofshape_constant_folding_load_dos.py \
--crafted-path /home/chopp3r/mfv-hunts/onnx_20260717/poc/onnxruntime-constantofshape-constant-folding-load-dos/model/onnx-constantofshape-load-dos.onnx \
--control-path /home/chopp3r/mfv-hunts/onnx_20260717/poc/onnxruntime-constantofshape-constant-folding-load-dos/model/small-control.onnx \
--python-bin /home/chopp3r/mfv-hunts/onnx_20260717/.venv/bin/python \
--mode default \
--repeats 1
Notes
- Harmless proof only: the effect is bounded local memory pressure and slower model load.
- No victim source modifications are required.
- The root cause is default optimizer behavior, not sparse tensor densification.
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support