Produce errors on invalid pdbpath supplied to compiler#25903
Produce errors on invalid pdbpath supplied to compiler#25903OmarTawfik merged 3 commits intodotnet:dev15.7.xfrom OmarTawfik:fix-23525-invalid-path-character
Conversation
|
Add tests:
|
|
@OmarTawfik What bug is this change fixing? #Resolved |
|
|
||
| if (PdbFilePath != null && !PathUtilities.IsValidFilePath(PdbFilePath)) | ||
| { | ||
| diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.FTL_InputFileNameTooLong, Location.None, PdbFilePath)); |
There was a problem hiding this comment.
FTL_InputFileNameTooLong [](start = 81, length = 24)
We probably should use name that is more accurately reflects the message. For example, FTL_InvalidInputFileName. #Closed
There was a problem hiding this comment.
Let's open a separate issue to follow up to avoid possible extra work for LOC team in dev15.7.x.
In reply to: 179337190 [](ancestors = 179337190)
|
@AlekseyTs this is fixing #23525 |
| public void InvalidPathCharacterInPathMap() | ||
| { | ||
| string filePath = Temp.CreateFile().WriteAllText("").Path; | ||
| var compiler = new MockCSharpCompiler(null, _baseDirectory, new[] |
There was a problem hiding this comment.
MockCSharpCompiler [](start = 31, length = 18)
Pass "/preferreduilang:en" switch otherwise the test is likely to fail on non-english machine #Closed
| public void InvalidPathCharacterInPdbPath() | ||
| { | ||
| string filePath = Temp.CreateFile().WriteAllText("").Path; | ||
| var compiler = new MockCSharpCompiler(null, _baseDirectory, new[] |
| <WorkItem(23525, "https://github.com/dotnet/roslyn/issues/23525")> | ||
| Public Sub InvalidPathCharacterInPathMap() | ||
| Dim filePath = Temp.CreateFile().WriteAllText("").Path | ||
| Dim compiler = New MockVisualBasicCompiler(Nothing, _baseDirectory, |
There was a problem hiding this comment.
MockVisualBasicCompiler [](start = 31, length = 23)
Pass "/preferreduilang:en" #Closed
| Dim result = Compilation.Emit(outStream, options:=New EmitOptions(pdbFilePath:="test\\?.pdb", debugInformationFormat:=DebugInformationFormat.Embedded)) | ||
|
|
||
| Assert.False(result.Success) | ||
| result.Diagnostics.Verify(Diagnostic(ERRID.FTL_InputFileNameTooLong).WithArguments("test\\?.pdb").WithLocation(1, 1)) |
There was a problem hiding this comment.
Diagnostic(ERRID.FTL_InputFileNameTooLong).WithArguments("test\?.pdb").WithLocation(1, 1) [](start = 42, length = 90)
Please include the actual error message in a comment as we usually do. #Closed
|
It looks like FTL_InputFileNameTooLong error is reported in more places than were adjusted. Are the other places doing proper validation? #Closed |
|
The places where invalid paths are checked and reported. In reply to: 378805570 [](ancestors = 378805570) |
|
@dotnet/roslyn-compiler this is ready for review. |
|
approved pending @AlekseyTs sign off. |
| { | ||
| try | ||
| { | ||
| if (string.IsNullOrEmpty(path)) |
There was a problem hiding this comment.
if (string.IsNullOrEmpty(path)) [](start = 16, length = 31)
Not very important, but this if can be extracted out of try.
| var fileInfo = new FileInfo(path); | ||
| return !string.IsNullOrEmpty(fileInfo.Name); | ||
| } | ||
| catch (Exception ex) when ( |
There was a problem hiding this comment.
when ( [](start = 33, length = 6)
Any particular reason to use when clause instead of using catch clause per specific exception type?
There was a problem hiding this comment.
Just a readability preference.
Customer scenario
In case a path was supplied to the compiler with an invalid character, we use that path without reporting errors and stamp it into the embedded pdb within the assembly. We should detect that and report the appropriate error.
Bugs this fixes
Fixes #23525
Workarounds, if any
None.
Risk
This is a breaking change, where instead of allowing invalid paths, we provide appropriate errors.
@dotnet/roslyn-compat-council will be notified and consulted before merging.
Performance impact
Negligible.
Is this a regression from a previous update?
No
Root cause analysis
Validation was not in place. Tests are now added.
How was the bug found?
Reported by a team member on GitHub.