pe: bound RVA reads and TLS slots by Misc.VirtualSize in intake_exe.py #753
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/759"
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 Ammmae0x on 2026-11-23T01:06:20Z.
Fixes #744
Change
inspect_executable()intools/intake_exe.pypreviously boundedsection_for(),read_rva(), and the TLS callbackslotscalculation bySizeOfRawDataalone and requiredpe.get_data(rva, length)to returnlengthfile-backed bytes. This rejected valid RVAs in zero-filled section virtual tails (Misc_VirtualSize > SizeOfRawData) and failed to clamp reads whenMisc_VirtualSize < SizeOfRawData.section_span(s)insideinspect_executable()to computemin(s.Misc_VirtualSize or s.SizeOfRawData, max(0, hdr.SizeOfImage - s.VirtualAddress)), matching the Windows PE loader andtools/pe_map.cpp.section_for()and the TLS callback slot bound to usesection_span(...).read_rva()to read the file-backed prefix viasection.get_data(rva, backed)(still raisingTruncated dataif short) and zero-pad the remaininglength - backeduninitialized virtual-tail bytes.check_tls_virtual_tail()intests/intake/check.pycovering positive cases (TLS directory inside a virtual tail, TLS directory straddlingSizeOfRawData, callback table straddlingSizeOfRawDatawith a zero terminator in the virtual tail, andMisc_VirtualSize == 0fallback) and four negative controls (exit2: unterminated callback table hittingMisc_VirtualSize, TLS directory read pastMisc_VirtualSize, non-executable callback in a straddling table, andMisc_VirtualSizeexceedingSizeOfImage).Verification
Tested on commit
401dea0(base356a7be), Windows x64 (MSVC 19.50.35727,CMake 4.2.3-msvc3,Ninja 1.12.1,Python 3.12.8):ctest --preset dev -N:328tests registered (matches baseline).cmake --build --preset dev --target intake_provider intake_delay intake_candidate&release: 0 errors, 0 warnings.ctest --preset dev --no-tests=error -R "static_exe_intake|conditional_import_paths|pe_inventory|forwarders|dependency_paths" -V:4/4 passed,0 skipped,0 failed(4.24s).ctest --preset release --no-tests=error -R "static_exe_intake|conditional_import_paths|pe_inventory|forwarders|dependency_paths" -V:4/4 passed,0 skipped,0 failed(3.99s)..\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: exit0(form coverage checks passed)..\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py: exit0(Checked 11 Markdown files and 137 links.)..\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py: exit0(Checked 618 tracked source, script and build/CI files: no bidirectional controls.).Evidence and follow-up
All new checks mutate temporary copies of the existing source-built
intake_candidatefixture intests/intake/check.py; no binary fixtures or external inputs were added.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T01:57:07Z.
Updated in
d9c1f23to match the #744 feedback:section_span()/section_for()) from file-backed bytes (raw_span()).read_rva()to prove the entire[rva, rva + length)span is file-backed before unpacking rather than zero-padding unbacked virtual tails (Unbacked or truncated data at RVA ...).ValueErrordiagnostics for TLS callback slots/tables truncated at eitherraw_span(straddling or inside the zero-filled tail) orsection_span(Truncated or unbacked TLS callback slot ...,Truncated TLS callback slot ...,Unterminated TLS callback table).tests/intake/candidate.cppandtests/intake/check.pyso.datais source-built with a raw prefix and zero-filled virtual tail (Misc_VirtualSize > SizeOfRawData) in both Debug and Release, coveringraw-prefixandMisc_VirtualSize == 0positive cases plus 9 exit-2 negative controls.dev(Debug) andrelease(/O2) (3/3intake/forwarder CTests,0warnings/errors, pure-Python checks passing), and all 4 required CI checks passed ond9c1f23.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T02:13:30Z.
Thanks for revising this around my earlier file-backed-only feedback. The landed #760 uses mapped-image semantics for TLS startup inspection. It validates and reads the file-backed prefix, then supplies the zero bytes the mapper provides within the virtual section. That differs from the earlier review guidance, so this revision deserves a separate decision. I’ll leave it open. The source-built raw-prefix, zero VirtualSize fallback and image-boundary checks are useful candidates for keeping with the landed behavior. The strict rejection of valid zero-filled TLS data would change that behavior.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T02:28:56Z.
Merged
upstream/main(including #760) in39d989cand updated the branch to keep the landed mapped-image semantics:tools/intake_exe.pyidentical toupstream/main(#760), preserving file-backed prefix reads + zero-filled virtual tails withinsection_span,Misc_VirtualSize or SizeOfRawDatafallback, andSizeOfImageclamping..dataraw-prefix + zero-tail fixture intests/intake/candidate.cpp(intake_raw_prefix+intake_zero_tail[4096]).check_virtual_tail_tls()intests/intake/check.py: source-built.dataraw-prefix TLS (tls-raw-prefix), populated TLS directory crossing into the zero tail (tls-dir-crossing-populated),Misc_VirtualSize == 0fallback (tls-zero-vsize), and negative controls forMisc_VirtualSizebounds, partial slots, invalid straddling slots, non-executable callbacks, andSizeOfImageclamping (tls-unterminated-vsize,tls-partial-vsize-slot,tls-partial-vsize-start,tls-slot-straddle,tls-past-vsize,tls-nonexec-tail-cb,tls-past-image).Verification on
39d989c(Windows 11, x64 MSVC):dev(Debug):cmake --build --preset dev --target intake_candidate intake_provider intake_delay intake_forward intake_forward_caller(0 errors, 0 warnings);ctest --preset dev --no-tests=error -R 'static_exe_intake|conditional_import_paths|bundled_export_forwarders' -V-> 3/3 passed.release(/O2):cmake --build --preset release --target intake_candidate intake_provider intake_delay intake_forward intake_forward_caller(0 errors, 0 warnings);ctest --preset release --no-tests=error -R 'static_exe_intake|conditional_import_paths|bundled_export_forwarders' -V-> 3/3 passed.tests/intake/paths_check.py,tests/form_coverage_check.py,tests/docs_links_check.py,tests/bidi_controls_check.py,tests/dependency_paths_check.py,tests/layout_chunks_check.py) -> all exited 0.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T03:15:21Z.
I reviewed
39d989cafter the policy change.tools/intake_exe.pyis byte-identical to merged #760. The PR now changes only the source-built intake fixture and its checks. I rebuilt both intake fixtures in an isolated Windows Release tree and ranctest --preset release --no-tests=error -R 'static_exe_intake|conditional_import_paths|bundled_export_forwarders': 3/3 passed. The added checks distinguish the mapped zero tail, raw prefix, VirtualSize fallback and the section/image bounds. Thanks for keeping those controls with the merged behavior.