Skip to content

detect include cycles in XMLParser::loadDocImpl - #1248

Open
aysha-afrah26 wants to merge 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:xml-include-cycle
Open

aysha-afrah26 wants to merge 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:xml-include-cycle

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

<include path="..."/> tags are followed recursively by XMLParser::PImpl::loadDocImpl, but unlike SubTree instantiation, which rejects cycles through the ancestors set added for #979, nothing stops a file from being included again by one of its own descendants. A file that includes itself, or two files that include each other (for example a shared subtree library that pulls in the file using it), makes createTreeFromFile load the same document over and over, keeping every copy alive in opened_documents, until the native stack runs out. Under ASan the process dies with a stack-overflow in tinyxml2 parsing beneath loadDocImpl, and in a release build it is a plain SIGSEGV the caller cannot catch, so a mistake in the XML takes down the whole executor instead of producing an error message. I noticed it while comparing the include path with the SubTree cycle check, and reproduced it with a self-including file of a few lines. The fix tracks the canonical paths of the files on the current include chain and throws a RuntimeError when a file is included by one of its own ancestors; entries are removed on the way back up, so diamond includes (the same file pulled in from two siblings) still load as before. The change stays inside the private PImpl, so there is no API or ABI change, and the two new tests in gtest_factory.cpp (CreateTreeFromFileWhichIncludesItself, CreateTreeFromFileWithIncludeCycle) abort with an ASan stack-overflow on master and pass with the fix.

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.

1 participant