Repository navigation
forget a rejected XML document in XMLParser - #1266
Merged
facontidavide merged 1 commit intoNov 7, 2026
Merged
facontidavide merged 1 commit into
facontidavide merged 1 commit into
Conversation
facontidavide
pushed a commit
to Quchaosheng/BehaviorTree.CPP
that referenced
this pull request
Nov 12, 2026
BehaviorTree#1266 dropped a document that failed to load, but the rollback stopped at the document boundary. If main.xml includes sub.xml and then fails, sub.xml has already registered its trees and they stay behind, and sub.xml becomes the first document, so instantiateTree() reads main_tree_to_execute from it. Take a snapshot before the call and restore it on failure. That also puts back a tree this call redefined, whose element lives in the document about to be erased. Fixes BehaviorTree#1282
facontidavide
added a commit
that referenced
this pull request
Nov 12, 2026
…from throwing (#1289) * Roll back a rejected XML load as a whole, not per document #1266 dropped a document that failed to load, but the rollback stopped at the document boundary. If main.xml includes sub.xml and then fails, sub.xml has already registered its trees and they stay behind, and sub.xml becomes the first document, so instantiateTree() reads main_tree_to_execute from it. Take a snapshot before the call and restore it on failure. That also puts back a tree this call redefined, whose element lives in the document about to be erased. Fixes #1282 * Don't let an exception escape Tree's destructor Tree::~Tree() calls haltTree(), and halting may throw: a TryCatch with catch_on_halt="true" ticks its catch child, and a tick is allowed to throw. An exception leaving a destructor calls std::terminate, so destroying such a tree aborted the process. Mark the destructor noexcept and swallow the exception. There is no caller left to report to. Fixes #1281 * Apply pre-commit (clang-format) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Roll back a rejected load once, at the top-level call; simplify tests - loadLastDocImpl is now only the top-level rollback point: <include> calls loadDocImpl directly, and on failure the call drops every document it opened (erase(doc_it, end())), so a valid included document no longer stays the "first document" whose main_tree_to_execute instantiateTree() reads. The snapshot also covers subtree_models and current_path, as listed in #1282, and is restored by move. - ~Tree(): drop the redundant noexcept (destructors are implicitly noexcept) and report a throwing halt on stderr, as FinallyNode does, instead of swallowing it silently (also fixes bugprone-empty-catch). - Tests: share TempSubdir/writeFile through test_helper.hpp (no getpid, which broke MSVC); move the destructor test next to the other catch_on_halt tests using lambda nodes and assert the catch child ran; add a first-document test; make the redefinition test go through a valid include of a rejected file (the old one passed on master); drop HaltStillRuns and RollbackKeepsEarlierTrees, which asserted nothing new. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Cover a non-std exception thrown while halting in Tree::~Tree() Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Davide Faconti <davide.faconti@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
UBSan,
createTreeFromTexton a factory that had rejected one malformed document before:loadFromTextandloadFromFileappend the newXMLDocumenttoopened_documentsbefore loading it, and a document thatloadDocImplrejects (XML that doesn't parse, a missing file, a tree that failsVerifyXML) stays in the list even though it registered no tree.instantiateTreewith an emptymain_tree_IDthen readsmain_tree_to_executefrom the root element of the first document in that list, which is null for a document that never parsed. A release build dereferences it.The factory keeps one parser for its whole life, so a single
registerBehaviorTreeFromText/Filecall that threw on a bad file (an application loading user-provided trees and carrying on after the error) is enough: every latercreateTreeFromText/FromFilewhose main tree can't be resolved from the new document (two trees and nomain_tree_to_execute, an emptyID) crashes instead of reporting the missing attribute, and a rejected document that did parse makesinstantiateTreelook for itsmain_tree_to_executeinstead of the valid document's tree. With the low-levelXMLParserAPI the same happens oninstantiateTree(blackboard)right after one failedloadFromText.The fix lives in the parser: a small
PImplhelper loads the document just appended and erases it again ifloadDocImplthrows, at the three places that push a document (loadFromFile,loadFromText, and the<include>loop, since a failed include would become the front once the top-level document is dropped).instantiateTreealso throws aRuntimeErrorinstead of callingfront()on an empty list. PrivatePImplplus one function body, no API or ABI change; included documents that did load keep their registered trees, so nothing points at a removed document.BehaviorTreeFactory.RejectedDocumentIsForgottenaborts under UBSan on master and passes with the fix; the full suite is green under ASan+UBSan and TSan.