[PR #1636] draw_ownership: enforce pointer segment upper bounds, EOF-bounded hexdump, and integer offset guards #1650

Open
opened 2026-11-26 20:21:59 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1636
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/draw-ownership-bounds-and-hexdump


📝 Commits (1)

  • 986798e draw_ownership: enforce pointer segment upper bounds, EOF-bounded hexdump, and integer offset guards

📊 Changes

2 files changed (+110 additions, -9 deletions)

View changed files

📝 tests/test_draw_ownership.py (+76 -0)
📝 tools/draw_ownership.py (+34 -9)

📄 Description

Item ID: DRAW-OWNERSHIP-BOUNDS-AND-HEXDUMP
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7154992847

Summary

Harden pointer range checks, hexdump EOF handling, and offset validation in tools/draw_ownership.py:

  • Pointer range upper bounds:
    • Enforce PTR_BASE <= raw < GRAPHICS_BASE in _system_pointer() so 0x60000000-based graphics pointers and higher values are explicitly rejected as non-system pointers rather than treated as out-of-range system offsets (or accepted on segments >= 256 MiB).
    • Cap reverse_pointers() upper bound at min(PTR_BASE + len(system), GRAPHICS_BASE) so graphics pointers never become system-segment edges.
    • Enforce GRAPHICS_BASE <= raw < GRAPHICS_LIMIT (0x70000000) in geometry_shape_check() so high/garbage values like 0x70000000 or 0xFFFFFFFF_FFFFFFFF are rejected.
  • EOF-bounded _hexdump(): stop emitting rows once at + row >= len(system) (preventing empty trailing rows past EOF in classify_parent() near segment end), convert slices via bytes(...) so memoryview works cleanly, and reject negative offsets/lengths.
  • Offset & index guards: reject bool and non-int offsets cleanly with TypeError across walk_chain(), walk_drawable(), classify_parent(), geometry_shape_check(), _u16()/_u32()/_u64(), and _hexdump(), and reject out-of-range caller-supplied reverse-index entries in classify_parent().
  • Tests (tests/test_draw_ownership.py): added BoundsAndHexdumpTests (6 test methods).

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU synthetic unit tests on macOS; no GPU or game data present)
  • python3 -W error -I tests/test_draw_ownership.py -v: 17/17 passed
  • Mutation check against unpatched main: ran=17 failures=10 errors=2
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/draw_ownership.py tests/test_draw_ownership.py: passed
  • python3 -m compileall -q tools/draw_ownership.py tests/test_draw_ownership.py: passed

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1636 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/draw-ownership-bounds-and-hexdump` --- ### 📝 Commits (1) - [`986798e`](https://github.com/ubiquitarianism/leonida/commit/986798eab22cc021aa2f1bd900112e2fa8062ba7) draw_ownership: enforce pointer segment upper bounds, EOF-bounded hexdump, and integer offset guards ### 📊 Changes **2 files changed** (+110 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_draw_ownership.py` (+76 -0) 📝 `tools/draw_ownership.py` (+34 -9) </details> ### 📄 Description Item ID: `DRAW-OWNERSHIP-BOUNDS-AND-HEXDUMP` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7154992847 ### Summary Harden pointer range checks, hexdump EOF handling, and offset validation in `tools/draw_ownership.py`: - **Pointer range upper bounds**: - Enforce `PTR_BASE <= raw < GRAPHICS_BASE` in `_system_pointer()` so `0x60000000`-based graphics pointers and higher values are explicitly rejected as non-system pointers rather than treated as out-of-range system offsets (or accepted on segments >= 256 MiB). - Cap `reverse_pointers()` upper bound at `min(PTR_BASE + len(system), GRAPHICS_BASE)` so graphics pointers never become system-segment edges. - Enforce `GRAPHICS_BASE <= raw < GRAPHICS_LIMIT` (`0x70000000`) in `geometry_shape_check()` so high/garbage values like `0x70000000` or `0xFFFFFFFF_FFFFFFFF` are rejected. - **EOF-bounded `_hexdump()`**: stop emitting rows once `at + row >= len(system)` (preventing empty trailing rows past EOF in `classify_parent()` near segment end), convert slices via `bytes(...)` so `memoryview` works cleanly, and reject negative offsets/lengths. - **Offset & index guards**: reject `bool` and non-`int` offsets cleanly with `TypeError` across `walk_chain()`, `walk_drawable()`, `classify_parent()`, `geometry_shape_check()`, `_u16()`/`_u32()`/`_u64()`, and `_hexdump()`, and reject out-of-range caller-supplied reverse-index entries in `classify_parent()`. - **Tests (`tests/test_draw_ownership.py`)**: added `BoundsAndHexdumpTests` (6 test methods). ### Verification - AI-assisted: yes - GPUs tested: none (CPU synthetic unit tests on macOS; no GPU or game data present) - `python3 -W error -I tests/test_draw_ownership.py -v`: 17/17 passed - Mutation check against unpatched `main`: `ran=17 failures=10 errors=2` - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed - `python3 -I scripts/check_no_game_data.py tools/draw_ownership.py tests/test_draw_ownership.py`: passed - `python3 -m compileall -q tools/draw_ownership.py tests/test_draw_ownership.py`: passed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1650
No description provided.