fix(relinker): accept empty TLS images beyond EOF on Windows #11000
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11000"
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 boykopovar/AnyPS5. Originally posted by plexerPK on 2026-10-25T13:56:57Z.
What
Accept a zero-length PT_TLS initialization image whose unused file offset is beyond EOF, matching the ELF reader contract. Keep bounds validation for nonempty images.
Tested
macOS arm64, Python 3.9.6, Release relinker-only build. Head
4f7f3318fa63f48e518a1773b2b1d1b796322f06on maine05ba6feebd000cfc316c1d1f00e37e030aa3d8b.Original code fails the new EOF+1 fixture; fixed code passes six added cases (zero-sized and BSS TLS at EOF, EOF+1 and UINT64_MAX). CTest: empty_tls, elf_reader_bounds, windows_tls_zero_fill and windows_tls_thread_pointer, 4/4 passed. Conventions and diff-check pass. Synthetic PE conversion only; no native Windows execution, game, console, GPU or hosted-CI result is claimed.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:13:16Z.
Review: APPROVED
Reviewed the zero-size ELF TLS bounds rule. When
FileSize == 0, the file offset is unused and no source bytes are copied; bounds checks remain in force for nonempty images. The six new EOF/EOF+1/UINT64_MAX cases cover both zero and nonzero memory sizes, while existing invalid-size and TLS-access cases remain. I configured and completed a clean Linux Release relinker-only build, then ranempty_tls,elf_reader_bounds,windows_tls_zero_fillandwindows_tls_thread_pointer: 4/4 passed. Hosted Linux, Windows, macOS arm64, macOS x86_64 and ASan relinker checks also pass.Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-25T15:04:43Z.
Review: APPROVED
Reviewed head
4f7f3318fmerged ontoupstream/main3a2c51afd(2026-10-25); the merge is clean.Environment: Windows 11 Home 10.0.26200, Intel i9-12900H, WinLibs GCC 15.2.0 UCRT, CMake 4.3.1, Ninja 1.13.2, Python 3.13.9,
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release.Results
long_pathsskipped. The one failure ispatch_advisor_unit. It fails the same way on plainmainon this machine, because the temp path contains a space (#10667), and it is unrelated.empty_tls,windows_tls_zero_fill,windows_tls_protected_entries,windows_tls_thread_pointerandmacos_empty_tlspass.test_empty_tls.pystarts every converted PE and expects exit code 42. All cases pass here, including the six new ones (offsets 0x1000, 0x1001 andUINT64_MAX, withp_memsz0 and 16). That covers the native execution your description leaves out.main'sWindowsTlsBuilder.cppunder this test, the run stops atempty-image-0-1001, where the relinker exits 2 withInvalid or unsupported ELF TLS layout.p_filesz0, nothing reads throughtls->Offsetafter the check. The template builder returns early for an empty image (WindowsTlsTemplateBuilder.cpp:7), and the offset otherwise only appears in exception text. The&&keepssource.size() - tls->Offsetfrom being evaluated for these inputs.ElfReaderalready skips the range check for an empty image (if (tls.FileSize == 0) continue;,ElfReader.cpp:181), so "matching the ELF reader contract" is accurate.check_conventions.py --base upstream/mainpasses with this title and body.Notes, nothing to change here
ElfReaderrejects an out-of-filePT_TLSfirst (PT_TLS initialization image is outside the file). That is unchanged frommain.Not checked: Linux and macOS locally.
I found nothing to change. For disclosure: my open #10947 touches Windows TLS relocations in
WindowsPePatcher.cppand its test, notWindowsTlsBuilder.cpportest_empty_tls.py, and none of my other open PRs touches these files.Written with AI assistance (Claude Code). I ran the build, the full suite with the native PE runs and the counter-check above on my Windows 11 machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:06:32Z.
Review: APPROVED
Reviewed exact head
4f7f3318fa63f48e518a1773b2b1d1b796322f06. I configured and built the relinker-only Release target locally.test_empty_tls.pypasses against the exact binary; focused CTestempty_tls,elf_reader_bounds,windows_tls_zero_fill, andwindows_tls_thread_pointerpasses 4/4.git diff --check upstream/main...HEADand conventions pass. The guard now bypasses file-offset bounds only for zero-file-size TLS images; nonempty images retain the original bounds check. Hosted Ubuntu, Windows, macOS arm64, macOS x86_64 and ASan relinker jobs pass; product jobs are skipped by path policy.