Skip to content

fix: mark unknown ONNX tensor dtypes inconclusive#915

Open
mldangelo-oai wants to merge 1 commit intomainfrom
mdangelo/codex/onnx-dtype-boundary-audit
Open

fix: mark unknown ONNX tensor dtypes inconclusive#915
mldangelo-oai wants to merge 1 commit intomainfrom
mdangelo/codex/onnx-dtype-boundary-audit

Conversation

@mldangelo-oai
Copy link
Copy Markdown
Contributor

@mldangelo-oai mldangelo-oai commented Apr 10, 2026

Summary

  • mark ONNX tensor-size validation failures as explicit inconclusive scan outcomes
  • fail closed when external-data tensor dtype mapping prevents size validation
  • preserve exit 1 precedence when a real security finding is present alongside an inconclusive validation result

Validation

  • uv run --python 3.12 --extra all-ci pytest tests/scanners/test_onnx_scanner.py -k "unknown_external_data_dtype or external_data_size_validation_uses_current_onnx_dtype_api"
  • uv run --python 3.12 --extra all-ci pytest tests/scanners/test_onnx_scanner.py
  • uv run ruff format modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run ruff check --fix modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run mypy modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run pytest -n auto -m "not slow and not integration" --maxfail=1
  • uv run ruff format --check modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run ruff check modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes
    • ONNX tensor data type validation failures are now reported as inconclusive scan outcomes instead of allowing scans to be marked clean. Validation failures now provide enhanced diagnostic information including tensor data type and exception metadata for further investigation.

@mldangelo-oai mldangelo-oai enabled auto-merge (squash) April 10, 2026 19:30
@github-actions
Copy link
Copy Markdown
Contributor

Workflow run and artifacts

Performance Benchmarks

Compared 6 shared benchmarks with a regression threshold of 15%.
Status: 0 regressions, 1 improved, 5 stable, 0 new, 0 missing.
Aggregate shared-benchmark median: 696.38ms -> 684.27ms (-1.7%).

Top improvements:

  • tests/benchmarks/test_scan_benchmarks.py::test_scan_pytorch_zip -31.4% (49.16ms -> 33.73ms, state_dict.pt, size=1.5 MiB, files=1)
Benchmark Target Size Files Baseline Current Change Status
tests/benchmarks/test_scan_benchmarks.py::test_scan_pytorch_zip state_dict.pt 1.5 MiB 1 49.16ms 33.73ms -31.4% improved
tests/benchmarks/test_scan_benchmarks.py::test_validate_file_type_pytorch_zip state_dict.pt 1.5 MiB 1 48.6us 47.5us -2.2% stable
tests/benchmarks/test_scan_benchmarks.py::test_scan_duplicate_directory duplicate-corpus 840.0 KiB 81 482.43ms 486.73ms +0.9% stable
tests/benchmarks/test_scan_benchmarks.py::test_scan_safe_pickle safe_model.pkl 49.4 KiB 1 28.03ms 27.86ms -0.6% stable
tests/benchmarks/test_scan_benchmarks.py::test_scan_mixed_directory mixed-corpus 1.7 MiB 54 136.55ms 135.74ms -0.6% stable
tests/benchmarks/test_scan_benchmarks.py::test_detect_file_format_safe_pickle safe_model.pkl 49.4 KiB 1 171.1us 170.6us -0.3% stable

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4bb0a6f8-4e38-4909-b69c-a8cb00184f0e

📥 Commits

Reviewing files that changed from the base of the PR and between f285a05 and e1f4359.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • modelaudit/scanners/onnx_scanner.py
  • tests/scanners/test_onnx_scanner.py

Walkthrough

The pull request modifies ONNX scanner behavior to treat tensor data type validation failures as inconclusive scan outcomes rather than clean. It introduces helper functions to mark scans inconclusive and updates exception handling in validation routines to use this new outcome classification.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Added changelog entry documenting the inconclusive outcome behavior for ONNX dtype validation failures.
Core Implementation
modelaudit/scanners/onnx_scanner.py
Introduced _mark_inconclusive_scan_result() and _finish_scan_result() helpers to handle inconclusive outcomes. Updated main scan control flow to fail closed when scan_outcome is inconclusive. Modified exception handlers in _validate_external_size() and _check_tensor_sizes() to mark scans inconclusive, elevated check severity from DEBUG to INFO, and enriched exception details with tensor metadata.
Tests
tests/scanners/test_onnx_scanner.py
Added _set_initializer_data_type() helper function and two test cases: one verifying unknown external data dtype triggers inconclusive outcome with INFO severity details, and another confirming security-critical issues take precedence over inconclusive status.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A scanner so wise, now sees the light—
When data types hide from proper sight,
Instead of faking clean, it humbly admits:
"I'm inconclusive!" with rigorous grit.
No false victories, just honest bits! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: marking unknown ONNX tensor data types as inconclusive scan outcomes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mdangelo/codex/onnx-dtype-boundary-audit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant