Skip to content

Fix out of memory error with large sarif reports #731

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 5 commits into from
Feb 13, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Cli/AttackSurfaceAnalyzerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,9 @@ internal static void WriteSarifLog(Dictionary<string, object> output, IEnumerabl
Formatting = Formatting.Indented,
};

File.WriteAllText(outputFilePath, JsonConvert.SerializeObject(log, settings));
using var target = File.CreateText(outputFilePath);
JsonSerializer serializer = JsonSerializer.Create(settings);
serializer.Serialize(target, log);
}

public static SarifLog GenerateSarifLog(Dictionary<string, object> output, IEnumerable<AsaRule> rules, bool disableImplicitFindings)
Expand Down Expand Up @@ -906,10 +908,11 @@ public static SarifLog GenerateSarifLog(Dictionary<string, object> output, IEnum

artifact.SetProperty("ResultType", compareResult.ResultType);

artifacts.Add(artifact);
int index = artifacts.Count - 1;
if (compareResult.Rules.Any())
{
artifacts.Add(artifact);
int index = artifacts.Count - 1;

foreach (var rule in compareResult.Rules)
{
var sarifResult = new Result();
Expand Down Expand Up @@ -942,6 +945,9 @@ public static SarifLog GenerateSarifLog(Dictionary<string, object> output, IEnum
{
if (!disableImplicitFindings)
{
artifacts.Add(artifact);
int index = artifacts.Count - 1;

var sarifResult = new Result();
sarifResult.Locations = new List<Location>()
{
Expand Down
Loading