OLD-7481: restore old upstream PR 7481 - rtti_scan: scan the last aligned qword of a section for a COL pointer #648

Manually merged
github merged 1 commit from gh-pr/648/head into gh-pr/648/base 2026-11-26 09:13:47 +00:00
Owner

@⁠aslan2142 on GitHub · 2026-11-24 10:52 UTC · original
aslan2142:rtti-scan-last-slot → main · +18 −1 · 2 files · 1 commits · merged 2026-11-25 22:21 UTC

Claimed in the coordination issue as: OLD-7481 #14

Restoration of my original pull request, old upstream PR 7481 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bca8c; no changes beyond the rebase.

What and why

  • scan_pe64_rtti looks for vtables by scanning each section's aligned qwords for a CompleteObjectLocator pointer.
  • The loop ran range(start, hi - 8, 8), so the qword at hi - 8 was never read, even though it is the last one that fits in the section.
  • A COL pointer stored in that last qword was missed, along with its vtable.
  • The fix sets the bound to hi - 7, so every qword that fits whole inside the section is read, and none past its end.
  • A new test in tests/test_rtti_scan.py puts the COL pointer in the last aligned qword of a synthetic .rdata. The vtable is found at VirtualSize 0x200, and nothing is found at 0x1FF, where the qword no longer fits.

Tested

Linux, Python 3.14.10, CPU only, synthetic PE images built by the tests (no game files).

  • python -I tests/test_rtti_scan.py:
    • on main, 30/30 pass;
    • on main with only the new test added, 31 run and 1 fails (the new test);
    • with the fix, 31/31 pass.
  • python -m compileall -q tools tests and git diff --check: clean.
  • python -I scripts/check_no_game_data.py tools/rtti_scan.py tests/test_rtti_scan.py: clean.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 10:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/648) `aslan2142:rtti-scan-last-slot` → `main` · +18 −1 · 2 files · 1 commits · merged 2026-11-25 22:21 UTC Claimed in the coordination issue as: OLD-7481 https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 Restoration of my original pull request, old upstream PR 7481 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bca8c675c62f9dbffc318ce6a59d57faf31; no changes beyond the rebase. ### What and why - `scan_pe64_rtti` looks for vtables by scanning each section's aligned qwords for a CompleteObjectLocator pointer. - The loop ran `range(start, hi - 8, 8)`, so the qword at `hi - 8` was never read, even though it is the last one that fits in the section. - A COL pointer stored in that last qword was missed, along with its vtable. - The fix sets the bound to `hi - 7`, so every qword that fits whole inside the section is read, and none past its end. - A new test in `tests/test_rtti_scan.py` puts the COL pointer in the last aligned qword of a synthetic `.rdata`. The vtable is found at `VirtualSize` 0x200, and nothing is found at 0x1FF, where the qword no longer fits. ### Tested Linux, Python 3.14.10, CPU only, synthetic PE images built by the tests (no game files). - `python -I tests/test_rtti_scan.py`: - on `main`, 30/30 pass; - on `main` with only the new test added, 31 run and 1 fails (the new test); - with the fix, 31/31 pass. - `python -m compileall -q tools tests` and `git diff --check`: clean. - `python -I scripts/check_no_game_data.py tools/rtti_scan.py tests/test_rtti_scan.py`: clean. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) AI-assisted (Claude Code, Claude Opus 5.5).
The vtable scan stopped at hi - 8 (exclusive), so the qword at hi - 8, the
last one that fits in the section, was never read. The bound is hi - 7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:13:46 +00:00
github manually merged commit 558b1b4e89 into gh-pr/648/base 2026-11-26 09:13:47 +00:00
Author
Owner

@⁠kirigayakazima on GitHub · 2026-11-24 11:50 UTC · original

Reviewed on Windows 11 x64 (Python 3.14.7, CPU only, synthetic PE images only — no game files) against head commit 558b1b4e896a8b301668e1632479bd02ee1e77da.

Verdict: Looks good — changing the scan stop bound from hi - 8 to hi - 7 fixes the off-by-one qword exclusion at section ends without reading past hi.

Checks run locally

  • Clean merge with main (21625bca): git merge-tree --write-tree upstream/main HEAD exited 0; git diff --check upstream/main...HEAD clean.
  • python -I tests/test_rtti_scan.py -v: 31 tests, OK (1 skipped) (test_report_keeps_permission_bits, POSIX permission bits on Windows).
  • Confirmed regression against main (21625bca): test_col_pointer_in_the_last_qword_of_a_section_is_scanned fails on upstream/main:tools/rtti_scan.py ([] != [{'rva': 8704, ...}]) and passes on this PR.
  • python -I tests/test_ci_registration.py: 15 tests, OK.
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py tools/rtti_scan.py tests/test_rtti_scan.py and python -m compileall -q tools tests: exit 0.

Additional synthetic boundary probes

  • VirtualSize sweep 0x1F8..0x208 (COL pointer at 0x1F8, executable slot pointer at 0x200):
    • 0x1F8..0x1FF -> []
    • 0x200..0x207 -> [{'rva': 0x2200, 'class': 'Probe', 'offset_in_object': 0, 'slots': 0}]
    • 0x208 -> [{'rva': 0x2200, 'class': 'Probe', 'offset_in_object': 0, 'slots': 1}]
  • Tiny/empty sections: VirtualSize = 1, 7 ([]), VirtualSize = 8 with COL pointer at offset 0 (slots: 0), and VirtualSize = 0, SizeOfRawData = 0 ([]) all behave cleanly without struct.error or negative-range issues.
  • Unaligned section VirtualAddress = 0x2004 (COL pointer at RVA 0x2008, aligned start (lo + 7) & ~7 = 0x2008): VirtualSize = 0x0B (hi = 0x200F) -> [], VirtualSize = 0x0C (hi = 0x2010) -> found Unalign (slots: 0).
  • Sibling bounds check: checked the other scan bounds in scan_pe64_rtti (COL check rva + 24 > len(img) and vtable slot loop while vt + 8 * (n + 1) <= hi); both already use exact inclusive bounds.

AI-assisted: yes

**@⁠kirigayakazima** on GitHub · 2026-11-24 11:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/648#issuecomment-7130627706) Reviewed on Windows 11 x64 (`Python 3.14.7`, CPU only, synthetic PE images only — no game files) against head commit `558b1b4e896a8b301668e1632479bd02ee1e77da`. **Verdict: Looks good** — changing the scan stop bound from `hi - 8` to `hi - 7` fixes the off-by-one qword exclusion at section ends without reading past `hi`. ### Checks run locally - Clean merge with `main` (`21625bca`): `git merge-tree --write-tree upstream/main HEAD` exited `0`; `git diff --check upstream/main...HEAD` clean. - `python -I tests/test_rtti_scan.py -v`: **31 tests, OK (1 skipped)** (`test_report_keeps_permission_bits`, `POSIX permission bits` on Windows). - Confirmed regression against `main` (`21625bca`): `test_col_pointer_in_the_last_qword_of_a_section_is_scanned` fails on `upstream/main:tools/rtti_scan.py` (`[] != [{'rva': 8704, ...}]`) and passes on this PR. - `python -I tests/test_ci_registration.py`: **15 tests, OK**. - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py tools/rtti_scan.py tests/test_rtti_scan.py` and `python -m compileall -q tools tests`: exit `0`. ### Additional synthetic boundary probes - **`VirtualSize` sweep `0x1F8..0x208`** (COL pointer at `0x1F8`, executable slot pointer at `0x200`): - `0x1F8..0x1FF` -> `[]` - `0x200..0x207` -> `[{'rva': 0x2200, 'class': 'Probe', 'offset_in_object': 0, 'slots': 0}]` - `0x208` -> `[{'rva': 0x2200, 'class': 'Probe', 'offset_in_object': 0, 'slots': 1}]` - **Tiny/empty sections**: `VirtualSize = 1, 7` (`[]`), `VirtualSize = 8` with COL pointer at offset `0` (`slots: 0`), and `VirtualSize = 0, SizeOfRawData = 0` (`[]`) all behave cleanly without `struct.error` or negative-range issues. - **Unaligned section `VirtualAddress = 0x2004`** (COL pointer at RVA `0x2008`, aligned start `(lo + 7) & ~7 = 0x2008`): `VirtualSize = 0x0B` (`hi = 0x200F`) -> `[]`, `VirtualSize = 0x0C` (`hi = 0x2010`) -> found `Unalign` (`slots: 0`). - **Sibling bounds check**: checked the other scan bounds in `scan_pe64_rtti` (COL check `rva + 24 > len(img)` and vtable slot loop `while vt + 8 * (n + 1) <= hi`); both already use exact inclusive bounds. AI-assisted: yes
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 03:56 UTC · original · approved these changes

Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). The last aligned qword starts at hi - 8, and range(..., hi - 8, 8) stopped before it; hi - 7 includes it without reading past the section.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 03:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/648#pullrequestreview-6051640698) · **approved these changes** Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). The last aligned qword starts at hi - 8, and range(..., hi - 8, 8) stopped before it; hi - 7 includes it without reading past the section. AI-assisted (Claude).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 22:21 UTC · original

Merged: rtti_scan scans the last aligned qword of a section for a COL pointer.

  • Changed since review: Nothing. It merges cleanly with main, and no review point is open.
  • Tested: tests/test_rtti_scan.py passes on main + this head (Linux, CPython 3.14).
  • Checked on main b8c44ce8e + 558b1b4e8: the semantic suite passes (492 files, 6,315 tests, 0 files failed); test_rtti_scan pass; the 15 docs and writer tests pass; check_no_game_data.py is clean on the 2 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 22:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/648#issuecomment-7176268290) Merged: `rtti_scan` scans the last aligned qword of a section for a COL pointer. - **Changed since review:** Nothing. It merges cleanly with `main`, and no review point is open. - **Tested:** `tests/test_rtti_scan.py` passes on `main` + this head (Linux, CPython 3.14). - **Checked on `main` `b8c44ce8e` + `558b1b4e8`:** the semantic suite passes (492 files, 6,315 tests, 0 files failed); `test_rtti_scan` pass; the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 2 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.