Sanitize .lnk/.ico filename leaf#1472
Open
shuaiyuanxx wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses start-menu shortcut/icon generation failures when app-provided names/IDs contain Windows-reserved filename characters (e.g., :), by sanitizing the .lnk and .ico filename leaf components while keeping the full app description intact for shortcut metadata.
Changes:
- Introduces
SanitizeFileName()to replace reserved/control characters, trim trailing space/dot, and (when modified) append a stable short hash to avoid collisions. - Applies sanitization to the
.icoleaf derived fromappIdand the.lnkleaf derived fromappDesc. - Updates inline documentation/comments around Start Menu link naming behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| WSLDVCPlugin/WSLDVCCallback.cpp | Uses sanitized filename leaves when composing .ico and .lnk paths. |
| WSLDVCPlugin/utils.h | Declares the new SanitizeFileName() helper with documentation. |
| WSLDVCPlugin/utils.cpp | Implements SanitizeFileName() (reserved/control char mapping, trimming, collision-avoidance hash suffix). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
An app whose Name= contains a Windows-reserved filename character
(e.g. "Code::Blocks") produced an illegal .lnk path; IPersistFile::Save
failed and the error was swallowed, so the app was silently missing
from the Start Menu with no diagnostic.
Add SanitizeFileName() and apply it to the filename leaves derived
from appDesc (.lnk) and appId (.ico). appDesc is kept intact for
SetDescription. Design:
- Reserved chars (\ / : * ? " < > |) and control chars map to '_'.
This is predictable and renders in any font, unlike look-alike
glyph substitution.
- Reserved DOS device names (CON, PRN, AUX, NUL, COM1..9, LPT1..9) are
illegal as a filename base even with an extension (e.g. "NUL.txt");
Windows keys this on the token before the first '.', so prepend '_'
to neutralize the base rather than relying on the hash suffix.
- A legal name is left byte-for-byte unchanged (no suffix), so the
common case is identical to today.
- '_' substitution can map distinct names ("A:B" and "A/B") onto the
same leaf; to avoid two apps' files overwriting each other, append a
short stable FNV-1a hash of the app's unique id (~XXXXXXXX) whenever
the name was altered. The hash is derived from appId, so it is unique
per app and deterministic across syncs.
The FileDB key remains appGroup\appId, so add/delete/sync bookkeeping
is unaffected. Trailing space/dot (illegal on Win32) are trimmed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
5b1531a to
08132a3
Compare
|
https://github.com/microsoft/WSL/blob/master/src/linux/init/escape.cpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed: #1009
An app whose Name= contains a Windows-reserved filename character (e.g. "Code::Blocks") produced an illegal .lnk path; IPersistFile::Save failed and the error was swallowed, so the app was silently missing from the Start Menu with no diagnostic.
Add SanitizeFileName() and apply it to the filename leaves derived from appDesc (.lnk) and appId (.ico). appDesc is kept intact for SetDescription.
Design:
The FileDB key remains appGroup\appId, so add/delete/sync bookkeeping is unaffected. Trailing space/dot (illegal on Win32) are trimmed.