Skip to content

Stop TargetDef::getMatchingTargets at an inheritance cycle - #3121

Open
shubhamrai9122-creator wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
shubhamrai9122-creator:fix-targetdef-inheritance-cycle
Open

shubhamrai9122-creator wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
shubhamrai9122-creator:fix-targetdef-inheritance-cycle

Conversation

@shubhamrai9122-creator

Copy link
Copy Markdown
Contributor

Description

Fixes #3096

TargetDef::getMatchingTargets() followed inherit with while (base). A targetdef that inherits from itself, or two that inherit from each other, never reached a null base, so the loop never ended and the result vector kept growing. NodeDef::getImplementation() calls it for any non-empty target, so it hung there too.

Changes

  • getMatchingTargets() keeps a StringSet of the targets it has returned and stops at the first repeat. A self-inheriting T gives { "T" }, a cycle T1 → T2 → T1 gives { "T1", "T2" }, and a normal chain is unchanged.
  • I stopped at the cycle rather than walking with traverseInheritance(), which throws ExceptionFoundCycle. That way getImplementation() returns nullptr for these documents instead of throwing from code paths that don't expect it, which is also what the regression test in the issue expects. validate() already reports the cycle (Cycle in element inheritance chain).

Testing

Added TargetDef inheritance cycle in MaterialXTest/MaterialXCore/Node.cpp, using the self- and mutual-cycle cases from the issue plus a normal two-level chain. Without the fix the test hangs (I ran it under a 20 s alarm and it was killed); with it, it passes. All Core test groups pass: 767 assertions in 38 test cases, run from the repository root.

A targetdef that inherits from itself, or a cycle of targetdefs, made
getMatchingTargets() loop forever while its result grew without bound,
which hung NodeDef::getImplementation() for that target. Each target is
now returned once and the walk stops at the first repeat.

Signed-off-by: shubhamrai9122-creator <shubhamrai9122@gmail.com>

This branch has not been deployed

No deployments
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.

Cyclic 'inherit' on TargetDefs causes an infinite loop and unbounded memory growth

1 participant