From ea49f4ce7a2b0a7d12d027c56609d3af2f653575 Mon Sep 17 00:00:00 2001 From: Shaopeng Li Date: Tue, 27 Dec 2022 14:24:29 -0800 Subject: [PATCH 1/3] fix hashData?.Sha256 == null --- .../Sdk/MultithreadedAnalyzeCommandBase.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs index 9974d2eec..ed7da031a 100644 --- a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs @@ -513,11 +513,11 @@ private async Task HashFilesAndPutInAnalysisQueueAsnc() loggerCache ??= new Dictionary(); - if (!loggerCache.TryGetValue(hashData.Sha256, out CachingLogger logger)) - { - logger = loggerCache[hashData.Sha256] = (CachingLogger)context.Logger; - } - context.Logger = logger; + context.Logger = hashData?.Sha256 == null + ? (CachingLogger)context.Logger + : loggerCache.TryGetValue(hashData.Sha256, out CachingLogger logger) + ? logger + : (loggerCache[hashData.Sha256] = (CachingLogger)context.Logger); } await readyToScanChannel.Writer.WriteAsync(index); From d16f0414891a3f01cfd3cfc7b52626094db7bc21 Mon Sep 17 00:00:00 2001 From: Shaopeng Li Date: Tue, 27 Dec 2022 14:53:26 -0800 Subject: [PATCH 2/3] add Release History --- src/ReleaseHistory.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index 52ee99dd0..0d0f20097 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -13,6 +13,7 @@ * 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) * 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) * 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) ## **v3.1.0** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/3.1.0) | [Driver](https://www.nuget.org/packages/Sarif.Driver/3.1.0) | [Converters](https://www.nuget.org/packages/Sarif.Converters/3.1.0) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/3.1.0) | [Multitool Library](https://www.nuget.org/packages/Sarif.Multitool.Library/3.1.0) From b4d2f68c6c7f21053a39e7752cdbfdce15330a80 Mon Sep 17 00:00:00 2001 From: Shaopeng Li Date: Tue, 27 Dec 2022 16:17:53 -0800 Subject: [PATCH 3/3] fix comment --- src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs index ed7da031a..eaf578d7f 100644 --- a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs @@ -513,11 +513,12 @@ private async Task HashFilesAndPutInAnalysisQueueAsnc() loggerCache ??= new Dictionary(); - context.Logger = hashData?.Sha256 == null - ? (CachingLogger)context.Logger - : loggerCache.TryGetValue(hashData.Sha256, out CachingLogger logger) + if (hashData?.Sha256 != null) + { + context.Logger = loggerCache.TryGetValue(hashData.Sha256, out CachingLogger logger) ? logger : (loggerCache[hashData.Sha256] = (CachingLogger)context.Logger); + } } await readyToScanChannel.Writer.WriteAsync(index);