Fix #672: prevent stack overflow from deeply-nested XML by facontidavide · Pull Request #1091 · BehaviorTree/BehaviorTree.CPP · GitHub
Skip to content

Fix #672: prevent stack overflow from deeply-nested XML#1091

Merged
facontidavide merged 1 commit into
masterfrom
fix/issue-672
Feb 2, 2026
Merged

Fix #672: prevent stack overflow from deeply-nested XML#1091
facontidavide merged 1 commit into
masterfrom
fix/issue-672

Conversation

@facontidavide

@facontidavide facontidavide commented Feb 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Added depth tracking to recursive XML parsing in VerifyXML() and recursivelyCreateSubtree()
  • Throws RuntimeError when XML nesting exceeds 256 levels, preventing stack overflow crashes
  • Added 11 new tests covering malformed XML: deeply-nested trees, missing required attributes, unknown node types, empty trees, duplicate IDs, and other edge cases

Test plan

  • Existing tests pass (331/331, excluding pre-existing flaky PostConditions.Issue601 timer race)
  • New BehaviorTreeFactory.MalformedXML_* tests verify depth limit and other malformed XML rejection
  • Verified that valid deep trees (within limit) still work

Closes #672

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Added protection against excessively deep XML nesting to prevent stack overflow conditions.
    • Improved error handling for malformed XML inputs with descriptive error messages.
    • Enhanced validation for empty or invalid behavior tree definitions.

…ack overflow

Adds a depth limit (256) to the recursive XML parsing functions in
VerifyXML() and recursivelyCreateSubtree(). Malformed XML with extreme
nesting now throws a clear RuntimeError instead of crashing.

Includes 11 new tests for malformed XML handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Feb 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.75%. Comparing base (2e72fb3) to head (3b01094).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/xml_parsing.cpp 78.57% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1091      +/-   ##
==========================================
+ Coverage   66.59%   66.75%   +0.15%     
==========================================
  Files         225      225              
  Lines       12853    12907      +54     
  Branches     1197     1205       +8     
==========================================
+ Hits         8560     8616      +56     
+ Misses       4243     4241       -2     
  Partials       50       50              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@facontidavide facontidavide merged commit f9a6f98 into master Feb 2, 2026
15 checks passed
@facontidavide facontidavide deleted the fix/issue-672 branch February 2, 2026 11:18
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.

stack-buffer-overflow in xml_parsing.cpp

1 participant