From a481c8147f30c7223d350e52c252ff73a7f2e4c6 Mon Sep 17 00:00:00 2001 From: Scott O'Neil Date: Tue, 27 Feb 2024 11:45:07 -0800 Subject: [PATCH] yar --- .../Sdk/MultithreadedAnalyzeCommandBase.cs | 20 ++-------- src/Sarif/EnumeratedArtifact.cs | 39 +------------------ src/Sarif/Notes.cs | 2 +- 3 files changed, 7 insertions(+), 54 deletions(-) diff --git a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs index 7334f53a8..7e3ab3a95 100644 --- a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs @@ -666,30 +666,18 @@ private async Task EnumerateFilesFromArtifactsProvider(TContext globalCont continue; } - long artifactSize = 0; - try - { - artifactSize = artifact.SizeInBytes.Value; - } - catch (Exception e) when (e is IOException || e is ArgumentException) - { - DriverEventSource.Log.ArtifactNotScanned(filePath, DriverEventNames.FilePathNotAllowed, 00, data2: null); - Notes.LogFileSkipped(globalContext, filePath, e.Message); - continue; - } - - if (artifactSize == 0) + if (artifact.SizeInBytes == 0) { DriverEventSource.Log.ArtifactNotScanned(filePath, DriverEventNames.EmptyFile, 00, data2: null); Notes.LogEmptyFileSkipped(globalContext, filePath); continue; } - if (!IsTargetWithinFileSizeLimit(artifactSize, globalContext.MaxFileSizeInKilobytes)) + if (!IsTargetWithinFileSizeLimit(artifact.SizeInBytes.Value, globalContext.MaxFileSizeInKilobytes)) { _filesExceedingSizeLimitCount++; - DriverEventSource.Log.ArtifactNotScanned(filePath, DriverEventNames.FileExceedsSizeLimits, artifactSize, $"{globalContext.MaxFileSizeInKilobytes}"); - Notes.LogFileExceedingSizeLimitSkipped(globalContext, filePath, artifactSize / 1000); + DriverEventSource.Log.ArtifactNotScanned(filePath, DriverEventNames.FileExceedsSizeLimits, artifact.SizeInBytes.Value, $"{globalContext.MaxFileSizeInKilobytes}"); + Notes.LogFileExceedingSizeLimitSkipped(globalContext, artifact.Uri.GetFilePath(), artifact.SizeInBytes.Value / 1000); continue; } diff --git a/src/Sarif/EnumeratedArtifact.cs b/src/Sarif/EnumeratedArtifact.cs index fdeb6dcf4..b4610a36d 100644 --- a/src/Sarif/EnumeratedArtifact.cs +++ b/src/Sarif/EnumeratedArtifact.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Text; -using System.Text.RegularExpressions; namespace Microsoft.CodeAnalysis.Sarif { @@ -21,7 +20,6 @@ public EnumeratedArtifact(IFileSystem fileSystem) internal byte[] bytes; internal string contents; - internal string cleanPath = string.Empty; private Encoding encoding; @@ -66,39 +64,6 @@ public byte[] Bytes set => this.bytes = value; } - public string CleanPath - { - get => GetCleanFilePath(Uri.OriginalString); - set => this.cleanPath = value; - } - - private readonly static Regex AbsoluteFilePathWithFileSchemeRegex = new Regex(@"file:(?:\/{3}|\/{2}\w+\/|\/{1})?(.+)", RegexOptions.Compiled | RegexOptions.CultureInvariant); - - private string GetCleanFilePath(string originalString) - { - if (this.cleanPath != string.Empty) - { - return this.cleanPath; - } - - if (originalString.StartsWith("file:")) - { - Match match = AbsoluteFilePathWithFileSchemeRegex.Match(originalString); - if (match.Success) - { - string separator = Path.DirectorySeparatorChar.ToString(); - this.cleanPath = match.Groups[1].Value.Replace("/", separator); - return this.cleanPath; - } - - throw new IOException("Invalid file path format."); - } - else - { - return originalString; - } - } - private (string text, byte[] bytes) GetArtifactData() { if (this.contents != null) @@ -121,7 +86,7 @@ private string GetCleanFilePath(string originalString) } // This is our client-side, disk-based file retrieval case. - this.Stream = FileSystem.FileOpenRead(CleanPath); + this.Stream = FileSystem.FileOpenRead(Uri.LocalPath); } RetrieveDataFromStream(); @@ -199,7 +164,7 @@ public long? SizeInBytes } else if (Uri != null && Uri.IsAbsoluteUri && Uri.IsFile) { - this.sizeInBytes = (long)FileSystem.FileInfoLength(CleanPath); + this.sizeInBytes = (long)FileSystem.FileInfoLength(Uri.LocalPath); } else if (this.Contents != null) { diff --git a/src/Sarif/Notes.cs b/src/Sarif/Notes.cs index 441513287..64899688a 100644 --- a/src/Sarif/Notes.cs +++ b/src/Sarif/Notes.cs @@ -37,7 +37,7 @@ public static void LogFileSkipped(IAnalysisContext context, string skippedFile, Path.GetFileName(skippedFile), reason)); - context.RuntimeErrors |= RuntimeConditions.OneOrMoreFilesSkipped; + context.RuntimeErrors |= RuntimeConditions.OneOrMoreFilesSkippedDueToExceedingSizeLimits; } public static void LogEmptyFileSkipped(IAnalysisContext context, string skippedFile)