tools/import_call_sites: bounds-check ordinary IAT slots and parse PE once in main #1855

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

@⁠kirigayakazima on GitHub · 2026-11-25 13:13 UTC · original
kirigayakazima:fix/import-call-sites-safety → main · +79 −20 · 2 files · 1 commits · open

Claimed in the coordination issue as: IMPORT-CALL-SITES-ORDINARY-IAT-BOUNDS-AND-SINGLE-PARSE (#1608)

What and why

  • Guard ordinary PE32+ import descriptors in tools/import_call_sites.py's import_entries() against zero or unmapped iat_rva / lookup RVAs (img.offset(..., 8)) and stop slot enumeration if img.offset(slot, 8) is None, matching the existing delay-import slot validation.
  • Extract _call_sites_from_image() and _unmatched_from_entries() so main() parses pe_inspect.PeImage and import_entries(img) once per CLI run instead of twice (while keeping public call_sites() and unmatched_selectors() signatures unchanged).
  • Add regression tests in tests/test_import_call_sites.py.

Tested

  • python -I tests/test_import_call_sites.py -v -> Ran 24 tests in 0.106s, OK.
  • Detached upstream/main (98c2f777) baseline worktree with updated tests/test_import_call_sites.py -> Ran 24 tests in 0.090s, FAILED (failures=4).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 6.127s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 14.536s, OK.
  • python -I scripts/check_no_game_data.py tools/import_call_sites.py tests/test_import_call_sites.py, python -I -m compileall -q tools/import_call_sites.py tests/test_import_call_sites.py, and git diff --check -> exit 0.

GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)

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)
**@⁠kirigayakazima** on GitHub · 2026-11-25 13:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1855) `kirigayakazima:fix/import-call-sites-safety` → `main` · +79 −20 · 2 files · 1 commits · open Claimed in the coordination issue as: IMPORT-CALL-SITES-ORDINARY-IAT-BOUNDS-AND-SINGLE-PARSE (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Guard ordinary PE32+ import descriptors in `tools/import_call_sites.py`'s `import_entries()` against zero or unmapped `iat_rva` / `lookup` RVAs (`img.offset(..., 8)`) and stop slot enumeration if `img.offset(slot, 8) is None`, matching the existing delay-import slot validation. - Extract `_call_sites_from_image()` and `_unmatched_from_entries()` so `main()` parses `pe_inspect.PeImage` and `import_entries(img)` once per CLI run instead of twice (while keeping public `call_sites()` and `unmatched_selectors()` signatures unchanged). - Add regression tests in `tests/test_import_call_sites.py`. ### Tested - `python -I tests/test_import_call_sites.py -v` -> `Ran 24 tests in 0.106s`, `OK`. - Detached `upstream/main` (`98c2f777`) baseline worktree with updated `tests/test_import_call_sites.py` -> `Ran 24 tests in 0.090s`, `FAILED (failures=4)`. - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 6.127s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 14.536s`, `OK`. - `python -I scripts/check_no_game_data.py tools/import_call_sites.py tests/test_import_call_sites.py`, `python -I -m compileall -q tools/import_call_sites.py tests/test_import_call_sites.py`, and `git diff --check` -> exit `0`. GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64) 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:08:48 +00:00
Author
Owner

@⁠madvillain91 on GitHub · 2026-11-25 13:30 UTC · original · reviewed

Independent Windows 11 26H2 (26300.9711) check at 9a936d9e8 against main 384abe5b0 (PR base 98c2f7777), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_import_call_sites.py (24/24 in 0.215s) and test_text_write_line_endings.py (3/3 in 19.667s), with check_no_game_data.py and compileall clean. Verified ordinary IAT descriptors with zero/unmapped RVAs are skipped, truncated IAT tables keep only whole mapped 8-byte slots, and main() parses the PE image and import entries once via _call_sites_from_image/_unmatched_from_entries while keeping public call_sites() and unmatched_selectors() intact. LGTM.

**@⁠madvillain91** on GitHub · 2026-11-25 13:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1855#pullrequestreview-6058506026) · **reviewed** Independent Windows 11 26H2 (26300.9711) check at 9a936d9e8 against main 384abe5b0 (PR base 98c2f7777), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_import_call_sites.py (24/24 in 0.215s) and test_text_write_line_endings.py (3/3 in 19.667s), with check_no_game_data.py and compileall clean. Verified ordinary IAT descriptors with zero/unmapped RVAs are skipped, truncated IAT tables keep only whole mapped 8-byte slots, and main() parses the PE image and import entries once via _call_sites_from_image/_unmatched_from_entries while keeping public call_sites() and unmatched_selectors() intact. LGTM.
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:37 UTC · original

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

python -m pytest -q tests/test_import_call_sites.py:

  • PR: 24 passed. main: 21 passed. The new tests pass on Windows.

(AI-assisted test run; output checked by hand.)

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1855#issuecomment-7167133257) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_import_call_sites.py`: - PR: 24 passed. main: 21 passed. The new tests pass on Windows. (AI-assisted test run; output checked by hand.)
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 17:27 UTC · original

Thanks. The new bounds check copies the existing delay-import check, but it only fires on a malformed executable: an image that loads has mapped IATs. The single-parse change saves one header parse.

Can you name a real input that reaches the new guard? Otherwise we'd rather not take the extra code.

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

**@⁠aslan2142** on GitHub · 2026-11-25 17:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1855#issuecomment-7169532795) Thanks. The new bounds check copies the existing delay-import check, but it only fires on a malformed executable: an image that loads has mapped IATs. The single-parse change saves one header parse. Can you name a real input that reaches the new guard? Otherwise we'd rather not take the extra code. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠MSedgeMC on GitHub · 2026-11-25 17:47 UTC · original · approved these changes

Verified on the PR branch: python3 -m unittest tests.test_import_call_sites -v -> 24 tests OK, including the new cases for zero/unmapped ordinary IAT, truncated IAT keeping only whole mapped slots, and parsing the PE image once in the CLI. These guard against reading out-of-range IAT slots from malformed PE data. Python-only, no game data.

**@⁠MSedgeMC** on GitHub · 2026-11-25 17:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1855#pullrequestreview-6062329087) · **approved these changes** Verified on the PR branch: python3 -m unittest tests.test_import_call_sites -v -> 24 tests OK, including the new cases for zero/unmapped ordinary IAT, truncated IAT keeping only whole mapped slots, and parsing the PE image once in the CLI. These guard against reading out-of-range IAT slots from malformed PE data. Python-only, no game data.
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/1855/head:github-bot/gh-1855'
git switch 'github-bot/gh-1855'

Merge

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