Skip to content

[pull] master from google:master#136

Merged
pull[bot] merged 6 commits into
threatcode:masterfrom
google:master
Jun 12, 2026
Merged

[pull] master from google:master#136
pull[bot] merged 6 commits into
threatcode:masterfrom
google:master

Conversation

@pull

@pull pull Bot commented Jun 12, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

DavidKorczynski and others added 6 commits June 12, 2026 11:15
Signed-off-by: David Korczynski <david@adalogics.com>
Signed-off-by: David Korczynski <david@adalogics.com>
Tracked in onnx/onnx#4902.

## Summary

Adds Python [atheris](https://github.com/google/atheris) fuzz targets
for the [ONNX](https://onnx.ai/) library, covering the main parsing,
validation, and transformation surfaces of the public API.

## Fuzz targets

| Target | API exercised | Input type |
|---|---|---|
| `fuzz_checker` | `checker.check_model(..., full_check=True)` | raw
bytes (checker accepts `bytes` natively) |
| `fuzz_model_loader` | `load_model_from_string` + graph traversal +
`check_model` | raw bytes |
| `fuzz_parser` | `parser.parse_model` | UTF-8 text (ONNX text format) |
| `fuzz_shape_inference` | `shape_inference.infer_shapes` with sampled
`check_type` and `strict_mode` | dual-path: raw bytes **or** structured
`ModelProto` built by `FuzzedDataProvider` |
| `fuzz_version_converter` | `version_converter.convert_version` | raw
bytes → ModelProto; tries version−1, version+1, and latest opset |

## Design notes

**C++ extension instrumentation.** ONNX's protobuf-based checker, shape
inference engine, and version converter are implemented in C++. The
build passes `$CFLAGS`/`$CXXFLAGS` via `pip install
--no-build-isolation` and sets `-DONNX_USE_ASAN=ON` via `CMAKE_ARGS`
when `$SANITIZER` is `address` or `undefined`, so both the Python layer
(via atheris) and the C++ extensions are instrumented.
`-DONNX_USE_ASAN=ON` covers both ASan and UBSan: ONNX's `CMakeLists.txt`
links `Sanitizer::address` and `Sanitizer::undefined` when this flag is
set, so no separate cmake flag is needed for UBSan.

**Seed corpora.** `make_seed_corpus.py` generates two seed zips:
- `fuzz_version_converter_seed_corpus.zip` — six serialized ONNX models
covering edge cases relevant to version conversion (missing inputs,
mixed opset versions).
- `fuzz_parser_seed_corpus.zip` — six ONNX text-format strings extracted
from
[`onnx/test/parser_test.py`](https://github.com/onnx/onnx/blob/main/onnx/test/parser_test.py),
covering basic graph parsing, multi-opset imports, metadata fields,
local function definitions with attribute references, type initializers,
and special float literals (`inf`, `-inf`, `nan`).

**Structured shape inference fuzzing.** `fuzz_shape_inference` uses two
input paths selected by a trailing toggle byte. The raw-bytes path feeds
the protobuf parser directly. The structured path uses
`FuzzedDataProvider` to construct `ModelProto` objects containing
subgraph-bearing ops (`If`, `Loop`, `Scan`), which drives the recursive
visitor inside `shape_inference` on most iterations. Both `strict_mode`
and `check_type` values are sampled per iteration.

**Recursion guard.** A `sys.setrecursionlimit(1000)` guard in
`fuzz_shape_inference` prevents a known unbounded-recursion DoS in the
shape inference engine (deeply nested subgraphs) from crashing the
fuzzer process. `RecursionError` is explicitly caught and suppressed so
the fuzzer continues finding unrelated bugs.

**API contract differences.** `checker.check_model` accepts
`Union[ModelProto, bytes, str, Path]` and handles deserialization
internally, so raw bytes are passed directly.
`shape_inference.infer_shapes` accepts `Union[ModelProto, str, Path]`
only, so the fuzzer deserializes first and passes the resulting
`ModelProto`.

## Testing

Built and ran locally with:
```
python infra/helper.py build_fuzzers onnx
python infra/helper.py run_fuzzer onnx <target>
```

---------

Signed-off-by: Andreas Fehlner <fehlner@arcor.de>
Signed-off-by: MuhammedHussein17 <muhammedbussnies@gmail.com>
Co-authored-by: MUHAMMED HUSSEIN <muhammedbussnies@gmail.com>
Signed-off-by: David Korczynski <david@adalogics.com>
Signed-off-by: David Korczynski <david@adalogics.com>
Signed-off-by: David Korczynski <david@adalogics.com>
@pull pull Bot locked and limited conversation to collaborators Jun 12, 2026
@pull pull Bot added the ⤵️ pull label Jun 12, 2026
@pull pull Bot merged commit e130e5c into threatcode:master Jun 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants