-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C#: Change random temp folder names to hash values #17257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d7314f
C#: Change random temp folder names to hash values
tamasvajk 79bd81f
C#: Adjust buildless package restore folders and tests
tamasvajk 0037ad4
C#: Adjust buildless source generator folders
tamasvajk a0dc20c
Fix hashed value on Windows
tamasvajk 07a5c20
Fix/add doc comments
tamasvajk 658326d
Work around some instability on Windows
tamasvajk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,16 +86,32 @@ public static void TryDelete(string file) | |
} | ||
|
||
/// <summary> | ||
/// Computes the hash of <paramref name="filePath"/>. | ||
/// Computes the hash of the file at <paramref name="filePath"/>. | ||
/// </summary> | ||
public static string ComputeFileHash(string filePath) | ||
{ | ||
using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); | ||
using var shaAlg = SHA256.Create(); | ||
var sha = shaAlg.ComputeHash(fileStream); | ||
var sha = SHA256.HashData(fileStream); | ||
return GetHashString(sha); | ||
} | ||
|
||
/// <summary> | ||
/// Computes the hash of <paramref name="input"/>. | ||
/// </summary> | ||
public static string ComputeHash(string input) | ||
{ | ||
var bytes = Encoding.Unicode.GetBytes(input); | ||
var sha = MD5.HashData(bytes); // MD5 to keep it shorter than SHA256 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried calculating the propability of collision for 1k elements on a 128bit hash - the calculator rounded it to 0 😂 |
||
return GetHashString(sha).ToUpper(); | ||
} | ||
|
||
private static string GetHashString(byte[] sha) | ||
{ | ||
var hex = new StringBuilder(sha.Length * 2); | ||
foreach (var b in sha) | ||
{ | ||
hex.AppendFormat("{0:x2}", b); | ||
} | ||
return hex.ToString(); | ||
} | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.expected
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
| Program.cs | | ||
| Views/Home/Index.cshtml | | ||
| _ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_test_test_Views_Home_Index_cshtml.g.cs | | ||
| test-db/working/implicitUsings/GlobalUsings.g.cs | | ||
| test-db/working/razor/EC52D77FE9BF67AD10C5C3F248392316/Microsoft.CodeAnalysis.Razor.Compiler/Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator/[...]_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_test_test_Views_Home_Index_cshtml.g.cs | |
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
4 changes: 2 additions & 2 deletions
4
csharp/ql/integration-tests/all-platforms/cshtml_standalone_disabled/Files.expected
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
| Program.cs | | ||
| test-db/working/implicitUsings/GlobalUsings.g.cs | | ||
| Program.cs:0:0:0:0 | Program.cs | | ||
| test-db/working/implicitUsings/GlobalUsings.g.cs:0:0:0:0 | test-db/working/implicitUsings/GlobalUsings.g.cs | |
17 changes: 1 addition & 16 deletions
17
csharp/ql/integration-tests/all-platforms/cshtml_standalone_disabled/Files.ql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,5 @@ | ||
import csharp | ||
|
||
private string getPath(File f) { | ||
result = f.getRelativePath() and | ||
not exists( | ||
result | ||
.indexOf("_semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") | ||
) | ||
or | ||
exists(int index | | ||
index = | ||
f.getRelativePath() | ||
.indexOf("_semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") and | ||
result = f.getRelativePath().substring(index, f.getRelativePath().length()) | ||
) | ||
} | ||
|
||
from File f | ||
where f.fromSource() or f.getExtension() = "cshtml" | ||
select getPath(f) | ||
select f |
2 changes: 1 addition & 1 deletion
2
csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.expected
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
| Program.cs | | ||
| Views/Home/Index.cshtml | | ||
| _ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_net6_test_test_Views_Home_Index_cshtml.g.cs | | ||
| test-db/working/implicitUsings/GlobalUsings.g.cs | | ||
| test-db/working/razor/EC52D77FE9BF67AD10C5C3F248392316/[...]/Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator/[...]_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_net6_test_test_Views_Home_Index_cshtml.g.cs | |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.