Skip to content

Commit 4c279b2

Browse files
When searching for the original file from a PDB, only allow absolute paths (#80804)
Without this check, if the PDB in question used path map to create a relative path, it's possible for this check to pass and end up handing around relative paths to the rest of the system (and the VS Shell). This eventually causes other things to break that expect full paths. Given a relative path would only work here by "luck" if the devenv current working directory happened to line up, it seems easiest just to assert it's an absolute path before going further. Fixes #79014 Fixes https://developercommunity.visualstudio.com/t/When-external-C-code-file-opened-more-t/10802958 (or at least I think the case that appeared in the customer's private dump)
2 parents bb57f46 + 7da3ef7 commit 4c279b2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentLoaderService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Microsoft.CodeAnalysis.MetadataAsSource;
1515
using Microsoft.CodeAnalysis.Shared.Utilities;
1616
using Microsoft.CodeAnalysis.Text;
17+
using Roslyn.Utilities;
1718

1819
namespace Microsoft.CodeAnalysis.PdbSourceDocument;
1920

@@ -167,7 +168,8 @@ internal sealed class PdbSourceDocumentLoaderService(
167168

168169
private SourceFileInfo? TryGetOriginalFile(SourceDocument sourceDocument, Encoding encoding, TelemetryMessage telemetry)
169170
{
170-
if (File.Exists(sourceDocument.FilePath))
171+
// The path in the PDB could be a relative path; since we don't have any path to compute an absolute path from, just disregard those.
172+
if (PathUtilities.IsAbsolute(sourceDocument.FilePath) && File.Exists(sourceDocument.FilePath))
171173
{
172174
var result = LoadSourceFile(sourceDocument.FilePath, sourceDocument, encoding, FeaturesResources.external, ignoreChecksum: false, fromRemoteLocation: false);
173175
if (result is not null)

0 commit comments

Comments
 (0)