Skip to content

[Core] Add nesting-depth limit to Loop::validate_and_infer_types and test TI nesting assert (CWE-674) - #37437

Draft
axinging wants to merge 1 commit into
openvinotoolkit:masterfrom
axinging:loop_gh716
Draft

[Core] Add nesting-depth limit to Loop::validate_and_infer_types and test TI nesting assert (CWE-674)#37437
axinging wants to merge 1 commit into
openvinotoolkit:masterfrom
axinging:loop_gh716

Conversation

@axinging

Copy link
Copy Markdown

Details:

Loop::validate_and_infer_types (loop.cpp:206) calls m_bodies[0]->validate_nodes_and_infer_types() which walks every body node and invokes each node's validate_and_infer_types(). If a body node is itself a v5::Loop, validation re-enters the same descent with no depth counter, producing one native C++ stack frame per nesting level. A sufficiently deep chain overflows the call stack and crashes the process (SIGSEGV / EXCEPTION_STACK_OVERFLOW).

This is the same defect shape as the If recursion,at a distinct location (Loop).

TensorIterator already has a hard assert in
revalidate_and_infer_types_for_body_ops() (tensor_iterator.cpp:47) that unconditionally blocks any TI nesting:

OPENVINO_ASSERT(... == nullptr, "No nested TensorIterator");

This is stronger than a depth guard — it forbids TI-in-TI entirely. No code change is needed for TI, but this assert was previously untested.

Fix: use the shared OV_VALIDATION_DEPTH_GUARD macro (introduced in the companion If PR) in Loop::validate_and_infer_types to guard against nesting deeper than kMaxValidationDepth = 64:

OV_VALIDATION_DEPTH_GUARD(this, "Loop");

Tests added:

  • type_prop.loop_nested_depth_limit_is_rejected (ov_core_unit_tests) — validates the Loop depth guard throws NodeValidationFailure at depth 1024.
  • type_prop.tensor_iterator_nested_is_rejected (ov_core_unit_tests) — locks TI's existing hard assert: nesting TI-in-TI at depth 2 throws AssertFailure with "No nested TensorIterator".

Tickets:

AI Assistance:

  • AI assistance used: yes
  • Bug root cause was found by AI.

…test TI nesting assert (CWE-674)

### Details:
`Loop::validate_and_infer_types` (loop.cpp:206) calls
`m_bodies[0]->validate_nodes_and_infer_types()` which walks every
body node and invokes each node's `validate_and_infer_types()`. If a
body node is itself a `v5::Loop`, validation re-enters the same
descent with no depth counter, producing one native C++ stack frame
per nesting level. A sufficiently deep chain overflows the call
stack and crashes the process (SIGSEGV / EXCEPTION_STACK_OVERFLOW).

This is the same defect shape as the If recursion,at a distinct
location (Loop).

`TensorIterator` already has a hard assert in
`revalidate_and_infer_types_for_body_ops()` (tensor_iterator.cpp:47)
that unconditionally blocks any TI nesting:
```cpp
OPENVINO_ASSERT(... == nullptr, "No nested TensorIterator");
```
This is stronger than a depth guard — it forbids TI-in-TI entirely.
No code change is needed for TI, but this assert was previously
untested.

Fix: use the shared `OV_VALIDATION_DEPTH_GUARD` macro (introduced
in the companion If PR) in `Loop::validate_and_infer_types` to
guard against nesting deeper than `kMaxValidationDepth = 64`:

```cpp
OV_VALIDATION_DEPTH_GUARD(this, "Loop");
```

Tests added:
- `type_prop.loop_nested_depth_limit_is_rejected`
  (ov_core_unit_tests) — validates the Loop depth guard throws
  `NodeValidationFailure` at depth 1024.
- `type_prop.tensor_iterator_nested_is_rejected`
  (ov_core_unit_tests) — locks TI's existing hard assert: nesting
  TI-in-TI at depth 2 throws `AssertFailure` with "No nested
  TensorIterator".

### Tickets:
- *CVS-192817*

### AI Assistance:
- *AI assistance used: yes*
- *Bug root cause was found by AI.*
@github-actions github-actions Bot added the category: Core OpenVINO Core (aka ngraph) label Aug 14, 2026
@sys-openvino-ci sys-openvino-ci added the ExternalIntelPR External contributor from Intel label Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: Core OpenVINO Core (aka ngraph) ExternalIntelPR External contributor from Intel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants