fix: prevent panics in shape inference when operands missing#2411
Open
jaweed3 wants to merge 1 commit into
Open
fix: prevent panics in shape inference when operands missing#2411jaweed3 wants to merge 1 commit into
jaweed3 wants to merge 1 commit into
Conversation
Concat, Squeeze, Gemm, Reshape, and the RNN family all access inputs[k] or outputs[k] without first checking that at least k+1 operands exist. A malformed ONNX file with too few inputs/outputs triggers an index-out-of-bounds panic. Add check_input_arity / check_output_arity guards so these cases produce a proper TractError instead. Closes sonos#2391.
|
🟡 Bench vs main — no speed regressions · 1 load/memory mover(s) Reference: main nightly, latest 2026-06-25 (0d old) · PR Speed — evaltime · prefill · decode no inference-speed regressions Load & memory (worst first)
🟢 3 improvement(s)
lower is better except prefill/decode (tok/s) · adaptive thresholds (max(floor, k×noise) vs the series' own history) · single-shot vs nightly reference · full report → run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Five ops (
Concat,Squeeze,Gemm,Reshape, and the RNN family) indexinputs[k]/outputs[k]in theirrules()without arity validation. A malformed ONNX with too few operands triggers an index-out-of-bounds panic instead of a graceful error.Fix
Add
check_input_arity/check_output_arityguard at the top of eachrules()before any indexing.hir/src/ops/array/concat.rscheck_input_arity(inputs, 1)?;onnx/src/ops/array/squeeze.rscheck_input_arity(inputs, 1)?;onnx/src/ops/math/gemm.rscheck_input_arity(inputs, 2)?;hir/src/ops/array/reshape.rscheck_input_arity(inputs, 2)?;onnx/src/ops/rec/common.rscheck_output_arity(outputs, output_count.max(1))?;Verification
Before:
tract concat_poc.onnx dump→ panic atconcat.rs:37After:
tract concat_poc.onnx dump→Error: Wrong input number. Rules expect 1, node has 0.Closes #2391.