Check section raw data against the end of the file as Windows does #142
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/143"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by danielradosa on 2026-11-21T17:04:14Z.
Change
pe_map_imagerefused any section whose copied raw data ran past the end of the file ("section outside image"), and otherwise trusted the raw range.LoadLibraryExWchecks raw data against the file by two rules only:PointerToRawData + SizeOfRawDatamay reach 4 GiB;SizeOfRawDatais nonzero, must have raw data that ends inside the file. This is compared without sector rounding.A section with
SizeOfRawData0 is not checked. If the last section has no raw data, no section is checked against the file size. The raw data of any other section may run past the end of the file or start after it: Windows maps it, and the missing bytes read as zero.pe_mapnow applies the same two rules, with distinct messages, and clamps its sector reads at the end of the file. This closes the open case listed in #111. Refs #46.Verification
cpu_native_sectiongains five patched copies of the register probe. In the probe,.rsrcis the last section;.rdataand.pdataare not.pe_maponmain.rdataraw data running past the file.pdataraw data after the file.pdatano raw data, offset after the file.pdataraw range reaching 4 GiBERROR_BAD_EXE_FORMAT.rsrcERROR_BAD_EXE_FORMATThe six earlier cases still match. The existing "rounded end past the file" case is the control for the truncated file: a shortened file loads when the last section's header ends at the new end of the file.
Windows 11 build 26300.9974, MSVC 19.51.36256, Python 3.14.4:
mainat47e990b: 5 of 11 cases differ.bvh_wave64_*, capability skips on an RTX 4060 and WARP), 0 failed.Evidence and follow-up
Exploratory runs, not part of the test, fixed the edges of both rules:
0x7ffffe00and0xfffffc00load, while0xfffffe00 + 0x200(exactly 2^32) fails.PointerToRawData0 withSizeOfRawData0xffffffffloads;0x10 + 0xfffffff0fails.PointerToRawData0 andSizeOfRawData0x10000 fails. WithSizeOfRawData0 it loads at any offset..rsrchas no raw data,.pdataraw data ending past the file still loads, so the check does not move to an earlier section.The
.rsrccases kept the resource directory entry intact. Windows also validates resource data on load, so each.rsrcfailure above was confirmed with the entry cleared as well.This covers images with
FileAlignment0x200, as in the source-built fixtures. TheFileAlignment0x1000case from #111 is still open.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T17:04:26Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
e1aa634ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:16:05Z.
The cancelled Windows job last logged
Start 43: cpu_native_sectionat 17:45:21 UTC and ended at 18:04:34 UTC with no result for that test. The two Linux jobs passed. I retried the Windows job once. Please check the section comparison on the Windows runner and report which named case starts but never returns, with a bounded timeout so the job can identify it. Cancelled Windows job.Imported from R0Y00/Xbox2Windows. Originally posted by danielradosa on 2026-11-22T12:02:47Z.
Thanks for the log. The branch has two updates:
start <section> <case>before it loads anything, stdout is line-buffered, andcpu_native_sectionhasTIMEOUT 120. If a load never returns, CTest ends the test, and the laststartline in its output names the case. As a check, I temporarily set the timeout to 0.3 s: the run ended with***Timeout, and its output stopped atstart .rdata raw data crossing a sector.mainmerged. The conflict was inmain()oftests/cpu/native_section_check.py, and both sides are kept: this PR's refusal count, and thecheck_protectionsandcheck_alignmentscalls from #418.A likely cause, not confirmed: the cancelled run on
afa72b5did not yet have theSetErrorMode(SEM_FAILCRITICALERRORS)call that #418 added to this test. This PR's two refusal cases (a raw range reaching 4 GiB, and a file one byte short of the last section) makeLoadLibraryExWfail with 193. On the runner, that failure could have opened a Bad Image dialog that nobody dismisses. The next Windows run will show whether that was the cause; if a case still hangs, the log now names it.Locally, on Windows 11 build 26300.9974, every
LoadLibraryExWcall in the test returns within 11 to 15 ms.cpu_native_sectionpasses in 0.3 s, covering all 11 cases plus the protection and alignment checks.