VDB
Sign up
MEDIUM6.2

GHSA-48m4-24cq-37qf

ONNX: Out-of-Bounds Read in RNN/GRU/LSTM Shape Inference (Old Opsets, Missing Rank Check)

Quick fix

GHSA-48m4-24cq-37qf — onnx: upgrade to the fixed version with the command below.

pip install --upgrade 'onnx>=1.22.0'

Details

## Summary

ONNX shape inference performed an out-of-bounds read when processing a malformed RNN, GRU, or LSTM node from opsets 1–6 whose first input had a rank other than three.

`RNNShapeInference_opset1_to_6()` checked whether the input shape was present but accessed `dim(0)` and `dim(1)` without first checking its rank. A crafted model could therefore terminate a process that called `onnx.shape_inference.infer_shapes()`. The model passed `onnx.checker.check_model()` before reaching the vulnerable path.

## Technical details

The vulnerable code read dimensions unconditionally:

```cpp if (hasInputShape(ctx, 0)) { const auto& first_input_shape = getInputShape(ctx, 0); seq_length = first_input_shape.dim(0); batch_size = first_input_shape.dim(1); } ```

For an undersized shape, protobuf's repeated-field access read outside the intended array in release builds. The observed result was SIGSEGV; sanitizer and debug builds terminated on a protobuf bounds check.

The newer opset 7–13 and opset 14+ inference paths already required the first input to have rank three and were not affected.

## Impact

An application that performs shape inference on an untrusted model can be terminated, causing denial of service. Exploitation does not require privileges or human interaction once the model is processed. No confidentiality or integrity impact was demonstrated.

## Affected versions

- Affected: ONNX through 1.21.0 - Patched: ONNX 1.22.0

The vulnerable schemas are limited to RNN and LSTM opsets 1–6 and GRU opsets 3–6.

## Remediation

Upgrade to ONNX 1.22.0 or later. The fix validates that the first input has rank three before accessing its dimensions.

- Fix: [onnx/onnx#7879](https://github.com/onnx/onnx/pull/7879) - Commit: [`92e541266`](https://github.com/onnx/onnx/commit/92e541266af5dd38cfa48aeb92206f4268a066cd)

The original malformed model was also re-tested against the published ONNX 1.23.2 wheel and correctly raises `InferenceError`.

## Severity

The vulnerable ONNX component processes the malicious model through a local library API or file boundary and is not itself bound to a network stack. Applications that expose ONNX model processing over a network should calculate an Environmental score with Modified Attack Vector set to Network.

Are you affected?

Enter the version of the package you're using.

Affected packages

PyPI/onnx
Introduced in: 0Fixed in: 1.22.0
Fixpip install --upgrade 'onnx>=1.22.0'

References

Check it before you install it

One call answers whether to add this package: known advisories, CISA KEV, and whether the name is a hallucinated or freshly squatted one. No key needed to try it.

curl -s https://vdb.ai.kr/v1/ai/check-packages \
  -H 'Content-Type: application/json' \
  -d '{"packages":["pkg:pypi/onnx"]}'