Skip to content

d3d12_guid_sites: a section's zero-filled tail is not the next section's bytes - #6512

Open
cynbun wants to merge 1 commit into
ItsNotRexed:mainfrom
cynbun:fix-guid-sites-virtual-tail
Open

cynbun wants to merge 1 commit into
ItsNotRexed:mainfrom
cynbun:fix-guid-sites-virtual-tail

Conversation

@cynbun

@cynbun cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claim: #6214 (comment) (finding + claiming, new item)

Cause

tools/d3d12_guid_sites.py maps an RVA to file bytes in three places that all accept va <= rva < va + max(VirtualSize, SizeOfRawData): Image.rva_to_offset (:96), Image.section_of (:110) and absolute_refs (:252). rva_to_offset then returns raw + (rva - va) with no clamp to SizeOfRawData, and read() slices 16 bytes from that offset.

The loader does not map an image that way. Past SizeOfRawData and inside VirtualSize (a .data BSS tail), memory is zero-filled. File bytes past VirtualSize are not mapped. So a lea to a BSS variable read 16 bytes of whatever section comes next in the file. When those bytes were GUID-shaped, they were reported as a GUID candidate "in .data" at the BSS address. Because candidates are keyed by value, the bogus reference also merged into the real constant's entry and took over its section and RVA.

pe_inspect.py _range() documents this rule ("File bytes past it are not mapped, as in runtime/src/pe_loader.cpp"), and #6339 just applied it to d3d12_iid_scan.py (span = min(vsize, rsize) if vsize else rsize). d3d12_guid_sites.py still had the old max().

Fix

  • Image.span(s): the section's in-memory size, VirtualSize, or SizeOfRawData when that is 0.
  • rva_to_offset: maps only within the span, and returns None past min(SizeOfRawData, span), because no file byte backs it.
  • read: returns the file bytes and then zeros for the zero-filled tail. It never reads past the section's span or into another section's raw data.
  • section_of and absolute_refs use the same span.

Tests

tests/test_d3d12_guid_sites.py gets a small pe32plus_sections() builder and one case. .data at 0x2000 has SizeOfRawData 0x200 and VirtualSize 0x400, and .rsrc at 0x3000 holds a GUID. One lea points at 0x2200 (zero-filled) and one at 0x3000. On origin/main the result is [(GUID, ".data", 0x2200)], with the .rsrc reference folded into the bogus entry. With the fix it is [(GUID, ".rsrc", 0x3000, refs=1)]. The case also checks read(0x21F8, 16) = 8 file bytes + 8 zeros and rva_to_offset(0x2200) is None. It fails before and passes after.

Tested on Linux, Python 3.14.8 (no GPU needed):

Synthetic PE images only, no game data.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…n's bytes

rva_to_offset, section_of and absolute_refs accepted an RVA anywhere in
va + max(VirtualSize, SizeOfRawData) and returned raw + (rva - va) with no
clamp to SizeOfRawData. A lea to a .data BSS variable (past the raw data,
inside VirtualSize) read 16 bytes of whatever section follows in the file,
and a GUID there was reported as a candidate in .data at the BSS address.

Map an RVA only within the section's in-memory span (VirtualSize, or
SizeOfRawData when that is 0), take file bytes only below
min(SizeOfRawData, span), and zero-fill the rest of a read, as
runtime/src/pe_loader.cpp loads it and as pe_inspect._range and
d3d12_iid_scan (ItsNotRexed#6339) already do.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Juryii

Juryii commented Nov 23, 2026

Copy link
Copy Markdown

Independently reviewed and tested a88598a1ae7d3454007a870fc22163c9b131b628 on Windows / CPython 3.12.5, CPU only: python -I tests/test_d3d12_guid_sites.py -v — 8 passed. Changed-file compilation and git diff --check pass; checkout clean.

Additional range-reader check: 17,400 comparisons against an independent byte-by-byte section model. Six raw sizes (including 0), seven virtual sizes (including the zero-size fallback), starts just outside and throughout each section, and reads of 0/1/7/16/32 bytes cover raw-only, zero-filled, and end-of-section cases. The same sweep also truncates the file's declared raw data to five available bytes. All reads and separately checked RVA-to-file offsets agree: missing raw bytes return a short result; only the actual virtual tail contributes zeros; bytes past the virtual span are excluded.

Negative control: loaded the actual parent version of d3d12_guid_sites.py and ran the new cross-section regression unchanged against it. It fails at the expected candidate comparison; head passes. The span/copy rule also matches the repository loader's min(SizeOfRawData, VirtualSize ? VirtualSize : SizeOfRawData) at runtime/src/pe_loader.cpp:1234.

No blocking findings within this scope. All PE images were synthetic; no package DLLs, game data, native loader execution or GPU used. AI-assisted review with Codex; tests, model comparisons and negative control executed locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants