-
Notifications
You must be signed in to change notification settings - Fork 93
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
Enqueue files filter #2599
Enqueue files filter #2599
Conversation
@@ -46,8 +46,10 @@ public static void LogExceptionLoadingTarget(IAnalysisContext context) | |||
throw new ArgumentNullException(nameof(context)); | |||
} | |||
|
|||
context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingTargetFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious what exception you got, guess its thrown by logger? Should we apply the same change to Warnings
?
} | ||
|
||
// '{0}' was skipped as its size ({1} kilobytes) exceeds the currently configured threshold ({2} kilobytes). | ||
context.Logger.LogConfigurationNotification( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Produces a console warning at runtime like so. Note that we include the full path name of the skipped file in the output. I produced this message by configuring the max file in kb argument via a config file, demonstrating that this is functional using actual client tool.
BINSKIM : warning WRN997.FileSkippedDueToSize : 'D:\repros\NetperfServiceReleaseFolder\VMAgents\Linux\NetPerfCanaryAppOrchestrator_artifact\NetPerfOrchestrator\resources\scripts\SecondaryNic.sh' was not analyzed as its size (4 kilobytes) exceeds the currently configured threshold (1 kilobytes).
@@ -12,6 +12,7 @@ | |||
|
|||
namespace Microsoft.CodeAnalysis.Sarif.Driver | |||
{ | |||
[Obsolete("AnalyzeCommandBase will be deprecated entirely soon. Use MultithreadedAnalyzeCommandBase instead.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -94,15 +95,16 @@ | |||
ExecutionException = ex; | |||
return FAILURE; | |||
} | |||
catch (Exception ex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -214,7 +213,7 @@ | |||
|
|||
// 1: First we initiate an asynchronous operation to locate disk files for | |||
// analysis, as specified in analysis configuration (file names, wildcards). | |||
Task<bool> enumerateFilesOnDisk = EnumerateFilesOnDiskAsync(options, rootContext); | |||
Task<bool> enumerateFilesOnDisk = EnumerateFilesOnDiskAsync(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -363,107 +367,129 @@ | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff is all screwed up here (in codeflow). This is the core new feature, we provide an overridable mechanism for filtering files at file enumeration time. This will allow binskim to check to see whether a file can be scanned. Currently, we let all files in and then they all get hashed (and then discarded), resulting in egregious slowdowns.
|
||
readyToHashChannel.Writer.Complete(); | ||
catch (Exception e) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so here's the source of some of the hangs that have been reported, if file enumeration raised an unhandled exception, we never closed the write channel. Oops.
@@ -115,7 +115,6 @@ protected override string ConstructTestOutputFromInputResource(string inputResou | |||
Quiet = true, | |||
PrettyPrint = true, | |||
Optimize = true, | |||
Kind = new List<ResultKind> { ResultKind.Fail }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -9,12 +9,6 @@ namespace Microsoft.CodeAnalysis.Sarif | |||
{ | |||
public class TestAnalyzeOptions : AnalyzeOptionsBase | |||
{ | |||
public TestAnalyzeOptions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…arif-sdk into enqueue-files-filter
@@ -89,13 +89,14 @@ | |||
if (!(ex is ExitApplicationException<ExitReason>)) | |||
{ | |||
// These exceptions escaped our net and must be logged here | |||
RuntimeErrors |= Errors.LogUnhandledEngineException(_rootContext, ex); | |||
Errors.LogUnhandledEngineException(_rootContext, ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!IsTargetWithinFileSizeLimit(file, _rootContext.MaxFileSizeInKilobytes, out long fileSizeInKb)) | ||
{ | ||
_ignoredFilesCount++; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question,
we use the ShouldEnqueue() to see if to add to sortedFiles list.
we use the IsTargetWithinFileSizeLimit to see if to add to _ignoredFilesCount.
Should we use the same logic, by just using the else
We can add more logics to ShouldEnqueue
in the future.
@@ -118,7 +129,7 @@ | |||
[Option( | |||
"max-file-size-in-kb", | |||
HelpText = "The maximum file size (in kilobytes) that will be analyzed.", | |||
Default = 1024)] | |||
public int MaxFileSizeInKilobytes { get; set; } = 1024; | |||
Default = -1)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a significant change that touches on some core driver concepts, worth a careful review.
AnalyzeCommandBase
as obsolete, we should delete it soon.@shaopeng-gh @LingZhou-gh @EasyRhin0 @suvamM @yongyan-gh
@rtaket @cfaucon, heads up: this SDK will emit skipped file warnings, as requested.