Skip to content

Validate the checksum of source on disk#57541

Merged
davidwengier merged 4 commits intodotnet:mainfrom
davidwengier:ValidateChecksum
Nov 5, 2021
Merged

Validate the checksum of source on disk#57541
davidwengier merged 4 commits intodotnet:mainfrom
davidwengier:ValidateChecksum

Conversation

@davidwengier
Copy link
Member

Fixes #57351

{
// TODO: Make sure the hash of the file is correct: https://github.com/dotnet/roslyn/issues/57351
return Task.FromResult<TextLoader?>(new FileTextLoader(sourceDocument.FilePath, Encoding.UTF8));
using var fileStream = new FileStream(sourceDocument.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete);
Copy link
Member

Choose a reason for hiding this comment

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

FileStream

May throw.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, wrap in

public static T PerformIO<T>(Func<T> function, T defaultValue = default)


if (fileChecksum.SequenceEqual(sourceDocument.Checksum))
{
return Task.FromResult<TextLoader?>(new FileTextLoader(sourceDocument.FilePath, Encoding.UTF8));
Copy link
Member

Choose a reason for hiding this comment

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

FileTextLoader

Since we already read the content of the file above wouldn't it be better to use that content here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, you're right. I was going to leave this for a follow up, as I suspect this API will change when the debugger bits are available, but I should probably just do it now :)

if (fileStream is not null)
{
// TODO: Don't hard code UTF8: https://github.com/dotnet/roslyn/issues/57350
var sourceText = SourceText.From(fileStream, Encoding.UTF8, sourceDocument.HashAlgorithm);
Copy link
Member

Choose a reason for hiding this comment

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

SourceText

Turns out this may also throw IO exceptions

@davidwengier davidwengier merged commit d1b9b73 into dotnet:main Nov 5, 2021
@ghost ghost added this to the Next milestone Nov 5, 2021
@davidwengier davidwengier deleted the ValidateChecksum branch November 5, 2021 19:18
333fred added a commit to 333fred/roslyn that referenced this pull request Nov 8, 2021
…sonly

* upstream/main: (829 commits)
  Re-enable BuildWithCommandLine test (dotnet#57584)
  Fix expected formatting in tests
  Simplify
  PR feedback
  Don't crash Use ExpressionBody on local functions in top level statements (dotnet#57571)
  Less linq
  Revert
  Update src/Features/VisualBasic/Portable/NavigationBar/VisualBasicNavigationBarItemService.vb
  Add test
  Simplify
  WIP
  Install .NET SDK in PR Validation pipeline
  Revert to VS2019 for PR Validation
  Update dependencies from https://github.com/dotnet/roslyn build 20211103.8
  Validate the checksum of source on disk (dotnet#57541)
  Clean up VsCodeWindowManager (dotnet#57582)
  Update VS editor package version
  Revert to VS2019 for official build
  Revert to VS2019 for official build
  StackFrame Parser/Lexer as EmbeddedLanguage (dotnet#56957)
  ...
333fred added a commit to 333fred/roslyn that referenced this pull request Nov 8, 2021
…-struct

* upstream/main: (829 commits)
  Re-enable BuildWithCommandLine test (dotnet#57584)
  Fix expected formatting in tests
  Simplify
  PR feedback
  Don't crash Use ExpressionBody on local functions in top level statements (dotnet#57571)
  Less linq
  Revert
  Update src/Features/VisualBasic/Portable/NavigationBar/VisualBasicNavigationBarItemService.vb
  Add test
  Simplify
  WIP
  Install .NET SDK in PR Validation pipeline
  Revert to VS2019 for PR Validation
  Update dependencies from https://github.com/dotnet/roslyn build 20211103.8
  Validate the checksum of source on disk (dotnet#57541)
  Clean up VsCodeWindowManager (dotnet#57582)
  Update VS editor package version
  Revert to VS2019 for official build
  Revert to VS2019 for official build
  StackFrame Parser/Lexer as EmbeddedLanguage (dotnet#56957)
  ...
@allisonchou allisonchou modified the milestones: Next, 17.1.P2 Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SourceLink] Ensure source file found on disk matches compiled DLL

4 participants