Skip to content

fix(relinker): reject Unicode output aliases on Windows - #6715

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
simonbronk:codex/windows-unicode-output-collisions
Oct 19, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
simonbronk:codex/windows-unicode-output-collisions

Conversation

@simonbronk

Copy link
Copy Markdown
Contributor

What

On a case-insensitive Windows directory, two not-yet-existing destinations such as Ä.b.bin.exe and ä.b.bin.exe refer 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 CompareStringOrdinal on 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 5d9dcc42d and rebuilt before submission.

  • The regression fails against the unmodified native baseline built from 44df21632. The affected collision implementation is unchanged in the current base.
  • Added CLI coverage for Latin Ä/ä, Greek Ω/ω and Cyrillic Ж/ж aliases, for both Linux and Windows output formats on Windows. An actual filesystem probe determines whether each pair aliases. Collision cases must fail before creating outputs and preserve every input.
  • Distinct Ä/a controls succeed; the two generated Windows executables return 42 and 43 respectively.
  • Four focused CTests pass: output_collisions, secondary_output_collisions, input_preservation, relinker_executables (13.23 s total).
  • Base conventions checker passes; published tree matches the validated source tree.

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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (OpenAI Codex)

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_destinations returns early outside nt, so the new cases do not run here. I ran the same cases on macOS (same prepare/main_fixture setup 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 OskarLGS left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 7332 core/relinker/main.cpp

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit 8816fd7 into boykopovar:main Oct 19, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the diff against main: SameOutputDestination now compares the filenames with CompareStringOrdinal (ignore-case) and throws if the comparison fails, instead of folding ASCII only. The new unicode_destinations test measures the real alias with samefile for Ä/ä, Ω/ω 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 main already made, so it is not blocking here. Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants