Skip to content

Produce errors on invalid pdbpath supplied to compiler#25903

Merged
OmarTawfik merged 3 commits intodotnet:dev15.7.xfrom
OmarTawfik:fix-23525-invalid-path-character
Apr 5, 2018
Merged

Produce errors on invalid pdbpath supplied to compiler#25903
OmarTawfik merged 3 commits intodotnet:dev15.7.xfrom
OmarTawfik:fix-23525-invalid-path-character

Conversation

@OmarTawfik
Copy link
Copy Markdown
Contributor

@OmarTawfik OmarTawfik commented Apr 3, 2018

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.

@OmarTawfik OmarTawfik added Bug Area-Compilers PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. labels Apr 3, 2018
@OmarTawfik OmarTawfik added this to the 15.7 milestone Apr 3, 2018
@OmarTawfik OmarTawfik self-assigned this Apr 3, 2018
@OmarTawfik OmarTawfik requested a review from a team as a code owner April 3, 2018 00:49
@OmarTawfik OmarTawfik removed the request for review from a team April 3, 2018 00:56
@OmarTawfik OmarTawfik changed the title Produce diagnostics on invalid pdb file path instead of crashing Use PathUtilities for calculating pdb name instead of System.IO.Path Apr 3, 2018
@OmarTawfik OmarTawfik changed the title Use PathUtilities for calculating pdb name instead of System.IO.Path Produce errors on invalid pdbpath supplied to compiler Apr 4, 2018
@OmarTawfik
Copy link
Copy Markdown
Contributor Author

OmarTawfik commented Apr 5, 2018

Add tests:

  • errors when parsing resource descriptors in both languages
  • path too long in PathUtilities. #Resolved

@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Apr 5, 2018

@OmarTawfik What bug is this change fixing? #Resolved


if (PdbFilePath != null && !PathUtilities.IsValidFilePath(PdbFilePath))
{
diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.FTL_InputFileNameTooLong, Location.None, PdbFilePath));
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTL_InputFileNameTooLong [](start = 81, length = 24)

We probably should use name that is more accurately reflects the message. For example, FTL_InvalidInputFileName. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #25944


In reply to: 179337455 [](ancestors = 179337455,179337190)

@OmarTawfik
Copy link
Copy Markdown
Contributor Author

OmarTawfik commented Apr 5, 2018

@AlekseyTs this is fixing #23525
I'll add a few tests and then tag you/compiler-team for review/mark it as ready. #Closed

public void InvalidPathCharacterInPathMap()
{
string filePath = Temp.CreateFile().WriteAllText("").Path;
var compiler = new MockCSharpCompiler(null, _baseDirectory, new[]
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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[]
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment #Closed

<WorkItem(23525, "https://github.com/dotnet/roslyn/issues/23525")>
Public Sub InvalidPathCharacterInPathMap()
Dim filePath = Temp.CreateFile().WriteAllText("").Path
Dim compiler = New MockVisualBasicCompiler(Nothing, _baseDirectory,
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@OmarTawfik OmarTawfik mentioned this pull request Apr 5, 2018
@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Apr 5, 2018

It looks like FTL_InputFileNameTooLong error is reported in more places than were adjusted. Are the other places doing proper validation? #Closed

@OmarTawfik
Copy link
Copy Markdown
Contributor Author

The places where invalid paths are checked and reported.


In reply to: 378805570 [](ancestors = 378805570)

@OmarTawfik OmarTawfik removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Apr 5, 2018
@OmarTawfik OmarTawfik requested a review from a team April 5, 2018 02:58
@OmarTawfik
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler this is ready for review.
@AlekseyTs thanks for taking an early look :)

@jaredpar
Copy link
Copy Markdown
Member

jaredpar commented Apr 5, 2018

approved pending @AlekseyTs sign off.

Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

{
try
{
if (string.IsNullOrEmpty(path))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when ( [](start = 33, length = 6)

Any particular reason to use when clause instead of using catch clause per specific exception type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a readability preference.

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (iteration 3)

@OmarTawfik OmarTawfik merged commit d23cc53 into dotnet:dev15.7.x Apr 5, 2018
@OmarTawfik OmarTawfik deleted the fix-23525-invalid-path-character branch April 5, 2018 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants