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

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

📋 Pull Request Information

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

Base: main ← Head: fix/import-call-sites-safety


📝 Commits (1)

  • 9a936d9 tools/import_call_sites: bounds-check ordinary IAT slots and parse PE once in main

📊 Changes

2 files changed (+79 additions, -20 deletions)

View changed files

📝 tests/test_import_call_sites.py (+40 -0)
📝 tools/import_call_sites.py (+39 -20)

📄 Description

Claimed in the coordination issue as: IMPORT-CALL-SITES-ORDINARY-IAT-BOUNDS-AND-SINGLE-PARSE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163426538)

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)

🔄 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/1855 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/import-call-sites-safety` --- ### 📝 Commits (1) - [`9a936d9`](https://github.com/ubiquitarianism/leonida/commit/9a936d9e8d17a147551237b591debf6461ecf619) tools/import_call_sites: bounds-check ordinary IAT slots and parse PE once in main ### 📊 Changes **2 files changed** (+79 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_import_call_sites.py` (+40 -0) 📝 `tools/import_call_sites.py` (+39 -20) </details> ### 📄 Description Claimed in the coordination issue as: IMPORT-CALL-SITES-ORDINARY-IAT-BOUNDS-AND-SINGLE-PARSE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163426538) ### 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) --- <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#1868
No description provided.