From dd629310b2c536909f0b2c12212d9a346e79aae4 Mon Sep 17 00:00:00 2001 From: Shaopeng Li Date: Thu, 29 Dec 2022 22:50:14 -0800 Subject: [PATCH 1/2] FEATURE : Provide overridable `ShouldComputeHashes` predicate method to prevent files from hashing. --- src/ReleaseHistory.md | 3 ++- src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index 3fa02043b..4c2f93939 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -16,10 +16,11 @@ * BUGFIX : Eliminate `IOException` and `DirectoryNotFoundException` exceptions thrown by `merge` command when splitting by rule (due to invalid file characters in rule ids). [#2513](https://github.com/microsoft/sarif-sdk/pull/2513) * BUGFIX : Fix classes inside NotYetAutoGenerated folder missing `virtual` keyword for public methods and properties, by regenerate and manually sync the changes. [#2537](https://github.com/microsoft/sarif-sdk/pull/2537) * BUGFIX : MSBuild Converter now accepts case insensitive keywords and supports PackageValidator msbuild log output. [#2579](https://github.com/microsoft/sarif-sdk/pull/2579) -* BUGFIX: Eliminate `NullReferenceException` when file hashing fails (due to file locked or other errors reading the file). [#2596](https://github.com/microsoft/sarif-sdk/pull/2596) +* BUGFIX : Eliminate `NullReferenceException` when file hashing fails (due to file locked or other errors reading the file). [#2596](https://github.com/microsoft/sarif-sdk/pull/2596) * FEATURE : Provide `PluginDriver` property (`AdditionalOptionsProvider`) that allows additional options to be exported (typically for command-line arguments). [#2599](https://github.com/microsoft/sarif-sdk/pull/2599) * FEATURE : Provide `LogFileSkippedDueToSize` that fires a warning notification if any file is skipped due to exceeding size threshold. [#2599](https://github.com/microsoft/sarif-sdk/pull/2599) * FEATURE : Provide overridable `ShouldEnqueue` predicate method to filter files from driver processing. [#2599](https://github.com/microsoft/sarif-sdk/pull/2599) +* FEATURE : Provide overridable `ShouldComputeHashes` predicate method to prevent files from hashing. [#2601](https://github.com/microsoft/sarif-sdk/pull/2601) * FEATURE : Allow external set of `MaxFileSizeInKilobytes`, which will allow SDK users to change the value. (Default value is 1024) [#2578](https://github.com/microsoft/sarif-sdk/pull/2578) * FEATURE : Add a Github validation rule `GH1007`, which requires flattened result message so GHAS code scanning can ingest the log. [#2580](https://github.com/microsoft/sarif-sdk/issues/2580) * FEATURE : Provide mechanism to populate `SarifLogger` with a `FileRegionsCache` instance. diff --git a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs index 7c5c1d2d0..4298165fa 100644 --- a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs @@ -378,6 +378,11 @@ protected virtual bool ShouldEnqueue(string file, TContext context) return shouldEnqueue; } + protected virtual bool ShouldComputeHashes(string file, TContext context) + { + return true; + } + private async Task EnumerateFilesOnDiskAsync(TOptions options) { try @@ -533,7 +538,9 @@ private async Task HashFilesAndPutInAnalysisQueueAsnc() TContext context = _fileContexts[index]; string localPath = context.TargetUri.LocalPath; - HashData hashData = HashUtilities.ComputeHashes(localPath, FileSystem); + HashData hashData = ShouldComputeHashes(localPath, context) + ? HashUtilities.ComputeHashes(localPath, FileSystem) + : null; context.Hashes = hashData; From afb8bbc9f2d886fea92ada0614ab268979907980 Mon Sep 17 00:00:00 2001 From: Shaopeng Li Date: Thu, 29 Dec 2022 22:57:12 -0800 Subject: [PATCH 2/2] use _rootContext --- src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs index 4298165fa..9050e842d 100644 --- a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs @@ -538,7 +538,7 @@ private async Task HashFilesAndPutInAnalysisQueueAsnc() TContext context = _fileContexts[index]; string localPath = context.TargetUri.LocalPath; - HashData hashData = ShouldComputeHashes(localPath, context) + HashData hashData = ShouldComputeHashes(localPath, _rootContext) ? HashUtilities.ComputeHashes(localPath, FileSystem) : null;