Skip to content

fix(htree): Reject UINT32_MAX pivot counts on pre-3.0 W3D loads - #3195

Open
CryoTheRenegade wants to merge 1 commit into
TheSuperHackers:mainfrom
CryoTheRenegade:fix/htree-pivot-count-overflow
Open

fix(htree): Reject UINT32_MAX pivot counts on pre-3.0 W3D loads#3195
CryoTheRenegade wants to merge 1 commit into
TheSuperHackers:mainfrom
CryoTheRenegade:fix/htree-pivot-count-overflow

Conversation

@CryoTheRenegade

@CryoTheRenegade CryoTheRenegade commented Aug 24, 2026

Copy link
Copy Markdown

For pre-3.0 W3D hierarchy trees, HTreeClass::Load_W3D increments header.NumPivots so a synthetic root pivot can be inserted. If malformed input supplies UINT32_MAX (0xffffffff), that increment wraps to zero.

Allocation is then skipped because NumPivots == 0, but read_pivots() still writes Pivot[0] when pre30 is true. That is a null pointer write.

This change:

  • Rejects a UINT32_MAX pivot count before the increment and returns LOAD_ERROR
  • Guards the synthetic root write in read_pivots() so it does not run unless Pivot is allocated and NumPivots >= 1

Found by clang-tidy

Prevent the synthetic-root increment from wrapping to zero so load does not skip allocation and then write Pivot[0].

Co-authored-by: Cursor <cursoragent@cursor.com>
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Reject overflowing pre-3.0 W3D hierarchy pivot counts

🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Rejects malformed pre-3.0 hierarchy counts before synthetic-root arithmetic can overflow.
• Guards synthetic-root initialization against missing or empty pivot allocations.
Diagram

graph TD
  A["W3D Header"] --> B{"Pre-3.0?"} -->|Yes| C{"Count max?"} -->|No| E["Allocate Pivots"] --> F["Read Pivots"] --> G{"Synthetic root?"} -->|Yes, valid| H["Initialize Root"]
  B -->|No| E
  C -->|Yes| D["Load Error"]
Loading
High-Level Assessment

The current defense-in-depth approach is appropriate: reject the invalid count before arithmetic, then enforce the allocation invariant at the write site. Relying on only the downstream guard would avoid the null write but would not reject the malformed header at its source.

Files changed (1) +7 / -0

Bug fix (1) +7 / -0
htree.cppPrevent legacy pivot-count overflow and null writes +7/-0

Prevent legacy pivot-count overflow and null writes

• Rejects UINT32_MAX pivot counts before pre-3.0 synthetic-root adjustment can wrap to zero. Verifies pivot storage exists and contains at least one element before writing the synthetic RootTransform pivot.

Core/Libraries/Source/WWVegas/WW3D2/htree.cpp

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can switch off images and animations for a plain-text comment

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

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