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

Open
github-bot wants to merge 1 commit from github-bot/gh-1636 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 06:39 UTC · original
IlyassRS3:fix/draw-ownership-bounds-and-hexdump → main · +110 −9 · 2 files · 1 commits · open

Item ID: DRAW-OWNERSHIP-BOUNDS-AND-HEXDUMP
Claim: #1608

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
**@⁠IlyassRS3** on GitHub · 2026-11-25 06:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1636) `IlyassRS3:fix/draw-ownership-bounds-and-hexdump` → `main` · +110 −9 · 2 files · 1 commits · open Item ID: `DRAW-OWNERSHIP-BOUNDS-AND-HEXDUMP` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:58:58 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 06:39 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 06:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1636#pullrequestreview-6052982718) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 10:35 UTC · original

Independent verification (Windows, Python 3.11.9 -I -W error): _require_int rejects bool/non-int across all entry points, _system_pointer bounded to [PTR_BASE, GRAPHICS_BASE), reverse_pointers high bound corrected, _hexdump EOF-bounded + bytes()-safe, geometry_shape_check window bounds consistent with segment layout, classify_parent index-source validation. Confirmed the bugs were real on base (trailing blank hexdump row past EOF, bool-as-offset-1). test_draw_ownership.py 17/17 OK; own bad-input probes all sane (negative->OutOfSegmentError, huge nbytes EOF-bounded, float/bool->TypeError); compileall + line-endings + check_no_game_data clean. Nit (pre-existing, unchanged): out-of-range classify_parent index still silently returns []. AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 10:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1636#issuecomment-7159899382) Independent verification (Windows, Python 3.11.9 `-I -W error`): `_require_int` rejects bool/non-int across all entry points, `_system_pointer` bounded to [PTR_BASE, GRAPHICS_BASE), `reverse_pointers` high bound corrected, `_hexdump` EOF-bounded + bytes()-safe, `geometry_shape_check` window bounds consistent with segment layout, `classify_parent` index-source validation. Confirmed the bugs were real on base (trailing blank hexdump row past EOF, bool-as-offset-1). `test_draw_ownership.py` 17/17 OK; own bad-input probes all sane (negative->OutOfSegmentError, huge nbytes EOF-bounded, float/bool->TypeError); compileall + line-endings + check_no_game_data clean. Nit (pre-existing, unchanged): out-of-range classify_parent index still silently returns []. AI-assisted verification.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1636/head:github-bot/gh-1636'
git switch 'github-bot/gh-1636'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1636'
git switch 'github-bot/gh-1636'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1636'
git switch 'github-bot/gh-1636'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1636'
git switch 'main'
git merge --squash 'github-bot/gh-1636'
git switch 'main'
git merge --ff-only 'github-bot/gh-1636'
git switch 'main'
git merge 'github-bot/gh-1636'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.