Repository navigation
fix(relinker): reject Unicode output aliases on Windows - #6715
adriadam10 merged 1 commit into
Conversation
jotitadev
left a comment
There was a problem hiding this comment.
macOS run on exact head 46cafca20f2702c6223da0ea950e562750b08bcb, applied on main 5d9dcc42d. 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.
- Full relinker-only suite: arm64 173/173; x86_64 170/173, the same three Python 3.9 failures as
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:
Main / --executable name |
APFS alias | Exit | Result |
|---|---|---|---|
Ä / ä, Ω / ω, Ж / ж |
yes | 0 | one .elf/.exe left: both executables were written to the same file |
A / a |
yes | 0 | same |
é (U+00E9) / e + U+0301 |
yes | 0 | same |
Ä / a |
no | 0 | two distinct outputs |
So on macOS the collision is not detected for any alias, including ASCII case, because the whole probe in SameOutputDestination is 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, so CompareStringOrdinal is 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.
OskarLGS
left a comment
There was a problem hiding this comment.
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.probe vs lower.probe with 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.bin and ä.b.bin were not seen as colliding on a case-insensitive volume) would help later readers.
Review done with AI assistance (Claude Code).
|
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.
|
|
Checked the diff against main: @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 |
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)