fix(relinker): reject Unicode output aliases on Windows #6715
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6715"
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 simonbronk on 2026-10-16T06:52:30Z.
What
On a case-insensitive Windows directory, two not-yet-existing destinations such as
Ä.b.bin.exeandä.b.bin.exerefer to the same output. The collision check only folded ASCII characters, so the secondary executable could overwrite the main output and the relinker still returned success. A synthetic reproduction changed the main executable's exit value from 42 to 43.Use
CompareStringOrdinalon native wide filenames for case-insensitive comparison and throw if the comparison fails. Retain the existing directory identity, directory case-sensitivity probe and existing-file identity checks.Related open work #6115 concerns missing companion destinations; #6328 concerns input hardlink preservation; #6127 restores existing collision checks. This change addresses non-ASCII aliases between generated outputs.
Tested
Windows, WinLibs GCC 15.2.0 r7 UCRT, Release relinker-only build, Python 3.12.14. Updated to main
5d9dcc42dand rebuilt before submission.44df21632. The affected collision implementation is unchanged in the current base.output_collisions,secondary_output_collisions,input_preservation,relinker_executables(13.23 s total).The host directory is case-insensitive. The case-sensitive directory branch and Linux/macOS hosts were not exercised. No full emulator build, complete CTest suite, game, GPU or FPS test was run. Existing platform-specific test skips remain.
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 jotitadev on 2026-10-16T07:34:02Z.
Review: COMMENTED
macOS run on exact head
46cafca20f2702c6223da0ea950e562750b08bcb, applied onmain5d9dcc42d. The change is under#ifdef _WIN32, so this is about the same aliases on the other case-insensitive host, not a problem with this PR.Machine: Apple M2 Max, macOS 27.2, Apple clang 21, Release relinker-only, default (case-insensitive) APFS volume. arm64 native with Python 3.14, and x86_64 under Rosetta with Python 3.9.6.
main(pr_overlap_tools,release_package,linux_fixed_base).unicode_destinationsreturns early outsident, so the new cases do not run here. I ran the same cases on macOS (sameprepare/main_fixturesetup and command line, without executing the outputs), for both Linux and Windows output, on both architectures:--executablenameÄ/ä,Ω/ω,Ж/ж.elf/.exeleft: both executables were written to the same fileA/aé(U+00E9) /e+ U+0301Ä/aSo on macOS the collision is not detected for any alias, including ASCII case, because the whole probe in
SameOutputDestinationis Windows-only (the case-only part is the follow-up listed in #4802). APFS also aliases canonically equivalent NFC/NFD names (last row). NTFS does not, soCompareStringOrdinalis right for this PR, but a macOS version cannot reuse a case-folding pre-filter alone; it would need to rely on the filesystem probe for those names.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by OskarLGS on 2026-10-17T21:37:44Z.
Review: COMMENTED
Reviewed on Linux (cannot run the new test, which is Windows-only). main.cpp compiles for Windows with MinGW-w64 GCC 13 (-fsyntax-only, -DUNICODE) on main and with this PR; CompareStringOrdinal and CSTR_EQUAL come from the windows.h that main.cpp already includes. The PR merges cleanly into current main and check_conventions.py passes.
One question about the decision path. CompareStringOrdinal(..., TRUE) now decides that the two names may alias, but the probe that follows still only tests ASCII case folding: it creates a lowercase
.anyps5-output-identity-*directory and looks it up with its ASCII letters uppercased. So forÄ/äthe relinker concludes "same file" from "this directory folds ASCII" plus "CompareStringOrdinal folds Ä/ä". Those two can disagree: CompareStringOrdinal uses the running system's uppercase table, while NTFS uses the volume's $UpCase table (written at format time), and SMB shares or other file systems fold with their own rules. A disagreement would turn into a false "Output paths collide", or a missed alias.The new test already avoids this by probing the real pair (
upper.probevslower.probewith os.path.samefile). Could the relinker do the same: create the probe entry inside the identity directory under the first output's file name and check whether the second output's file name resolves to it? The identity directory inherits the parent's per-directory case-sensitivity flag, so the probe would measure the actual pair on the actual volume, and the ASCII-only probe would no longer be needed.Minor: the commit has no body; a line on what was broken (only ASCII letters were folded, so
Ä.b.binandä.b.binwere not seen as colliding on a case-insensitive volume) would help later readers.Review done with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T14:54:56Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/relinker/main.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T09:07:27Z.
Checked the diff against main:
SameOutputDestinationnow compares the filenames withCompareStringOrdinal(ignore-case) and throws if the comparison fails, instead of folding ASCII only. The newunicode_destinationstest measures the real alias withsamefilefor Ä/ä, Ω/ω and Ж/ж (plus an Ä/a control) and expects a collision error with no outputs created. It would not see a collision on the old ASCII-only fold. The relinker Windows/Linux/macOS jobs are green, and the Windows job is the one that runs the new test.@OskarLGS's point (the identity probe after the name comparison still folds ASCII only, and the system upcase table could differ from the volume's) is a fair hardening idea, but it is the same assumption
mainalready made, so it is not blocking here. Merged.