[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
Draft
[Core] Add nesting-depth limit to Loop::validate_and_infer_types and test TI nesting assert (CWE-674)#37437axinging wants to merge 1 commit into
axinging wants to merge 1 commit into
Conversation
…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.*
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.
Details:
Loop::validate_and_infer_types(loop.cpp:206) callsm_bodies[0]->validate_nodes_and_infer_types()which walks every body node and invokes each node'svalidate_and_infer_types(). If a body node is itself av5::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).
TensorIteratoralready has a hard assert inrevalidate_and_infer_types_for_body_ops()(tensor_iterator.cpp:47) that unconditionally blocks any TI nesting: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_GUARDmacro (introduced in the companion If PR) inLoop::validate_and_infer_typesto guard against nesting deeper thankMaxValidationDepth = 64:Tests added:
type_prop.loop_nested_depth_limit_is_rejected(ov_core_unit_tests) — validates the Loop depth guard throwsNodeValidationFailureat 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 throwsAssertFailurewith "No nested TensorIterator".Tickets:
AI Assistance: