microsoft / microsoft/CsWinRT

WinRT.Host misidentifies standard casing and probes outside its directory

Open
#2,550 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
665
Forks
134
Avg merge
1d 3h
Merged PRs (30d)
32

Description

Description

WinRT.Host.dll is the standard non-NativeAOT implementation name emitted by Microsoft.Windows.CsWinRT.Authoring.targets, but WinRT.Host.cpp recognizes its generic-host convention only when the host filename is exactly lowercase winrt.host.dll.

if (host_file.wstring() != L"winrt.host.dll")

On Windows, a normal WinRT.Host.dll is therefore treated as a renamed host. The renamed-host probing then repeatedly calls rfind('.') on the complete module path:

std::size_t count = target_path.rfind('.');
target_path.resize(count);

After exhausting the filename suffixes, this can consume a dot in a parent directory and probe outside the host directory.

Minimal reproduction
  1. Put the generic host and WinRT.Host.runtimeconfig.json in a dotted directory, for example C:\build\Sample.Packaging\AppX\WinRT.Host.dll.
  2. Put the actual authored assembly next to the host, for example C:\build\Sample.Packaging\AppX\Contoso.Component.dll, and activate Contoso.Component.Widget.
  3. Place an unrelated C:\build\Sample.dll adjacent to Sample.Packaging.
  4. Activate the runtime class.

Actual probe sequence includes:

C:\build\Sample.Packaging\AppX\WinRT.Host.Server.dll
C:\build\Sample.Packaging\AppX\WinRT.Server.dll
C:\build\Sample.Packaging\AppX\WinRT.dll
C:\build\Sample.Server.dll
C:\build\Sample.dll

The last candidate is outside the host directory. If it exists, the host loads it and class lookup can fail with CLASS_E_CLASSNOTAVAILABLE; otherwise class-name convention probing never reaches the expected Contoso.Component.dll.

Expected behavior

A generic host installed as the normal CsWinRT-authored WinRT.Host.dll should use class-name convention probing and resolve Contoso.Component.Widget to Contoso.Component.dll beside the host. Renamed-host probing must never traverse above the host directory.

Proposed fix
  1. Compare the generic-host filename case-insensitively.
  2. For renamed hosts, peel dot-separated suffixes from host_module.filename() only, then combine each candidate filename with the original parent path.
Affected versions

The source file is identical in CsWinRT 2.3.1 and 3.0.0-preview.260319.2 (src/Authoring/WinRT.Host/WinRT.Host.cpp, blob 82566f5995536eb4d4432058db7ee2d57c2d5570), so the current 3.0 preview is also affected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/Authoring/WinRT.Host/WinRT.Host.cpp and reproduce the issue using a dotted host directory and the filenames in the report. Check the generic-host filename comparison and the renamed-host probe candidates. Done means normal WinRT.Host.dll resolves the authored assembly beside it, while renamed-host probing does not leave the host directory.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.