Fix markdown image hover preview for paths exceeding MAX_PATH on Windows#309363
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix markdown image hover preview for paths exceeding MAX_PATH on Windows#309363yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…dows On Windows, Electron's registerFileProtocol handler fails to load files whose absolute path exceeds MAX_PATH (259). This breaks markdown image hover previews (and any other vscode-file:// resource) for deeply nested files, even though the preview rendering itself works because it goes through a different code path. Work around the underlying Electron/Win32 limitation (electron/electron#49101) by prefixing paths with '\?\' (or '\?\UNC\' for UNC paths) before handing them back to Electron's protocol callback. The extended-length prefix is only applied on Windows and only when the resolved path is close to or over the limit, so normal short paths are unaffected. The validRoots / validExtensions allow-list checks are still performed against the normalized (unprefixed) path so the security boundary is unchanged. Fixes microsoft#261880
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.
What / Why
On Windows, the markdown image hover preview fails when a file's absolute path exceeds
MAX_PATH(259 characters), even though the full preview panel renders the image correctly. The root cause is that the hover preview loads images through Electron'sregisterFileProtocol(thevscode-file://handler inProtocolMainService), and Electron's handler bottoms out in a Win32 API call that does not use the extended-length path prefix — so anything overMAX_PATHis rejected by the OS. This was diagnosed in the issue thread by @busorgin and tracked upstream at electron/electron#49101.Fixes #261880
Fix
Before handing a resolved path to Electron's protocol callback, transform it on Windows to the extended-length form:
C:\...becomes\?\C:\...\server\share\...becomes\?\UNC\server\share\...This opts the underlying Win32 APIs into extended-length path mode, which bypasses the
MAX_PATHlimit. The transformation is:validRoots/validExtensionsallow-list checks continue to run against the original normalized path, so the security boundary aroundvscode-file://is unchanged.Testing
toWindowsLongPathIfNeeded.Notes