libxmlparser: fix unsafe XMLNode array handling - #29
Conversation
XMLNode has non-trivial copy and destruction semantics because it maintains a reference-counted XMLNodeData pointer. Moving its instances with realloc() or memmove() bypasses those semantics and is undefined behavior. Allocate child arrays with new[] and relocate active nodes through their copy assignment operator. Track the allocated capacities of all internal arrays so shrinking them in exactMemory() remains compatible with later add operations. This also fixes a pre-existing heap overflow when a parsed node was modified afterwards. Finally, check seek, size, allocation and fread results in parseFile() instead of parsing an uninitialized or partially filled buffer.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe XML parser now tracks array capacities, resizes child arrays with ChangesXML parser memory and file handling
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to This change makes XML node storage and cleanup array-compatible, preserves node lifetime semantics during relocation, and returns parser errors for file-read failures. No actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
XMLNode has non-trivial copy and destruction semantics because it maintains a reference-counted XMLNodeData pointer. Moving its instances with realloc() or memmove() bypasses those semantics and is undefined behavior.
Allocate child arrays with new[] and relocate active nodes through their copy assignment operator. Track the allocated capacities of all internal arrays so shrinking them in exactMemory() remains compatible with later add operations. This also fixes a pre-existing heap overflow when a parsed node was modified afterwards.
Finally, check seek, size, allocation and fread results in parseFile() instead of parsing an uninitialized or partially filled buffer.
Summary by CodeRabbit
Bug Fixes
Maintenance