Skip to content

Commit

Permalink
Handle duplicate DiffId docker image layers (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
cobya authored Feb 9, 2022
1 parent 60e2b6d commit 9605418
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ await DockerService.TryPullImageAsync(image, cancellationToken)))
}
catch (Exception e)
{
Logger.LogWarning($"Processing of image {image} failed with exception: {e.Message}");
using var record = new LinuxContainerDetectorImageDetectionFailed
{
ExceptionType = e.GetType().ToString(),
Expand Down Expand Up @@ -153,6 +154,7 @@ await DockerService.TryPullImageAsync(image, cancellationToken)))
}
catch (Exception e)
{
Logger.LogWarning($"Scanning of image {kvp.Key} failed with exception: {e.Message}");
using var record = new LinuxContainerDetectorImageDetectionFailed
{
ExceptionType = e.GetType().ToString(),
Expand Down
10 changes: 6 additions & 4 deletions src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ public async Task<IEnumerable<LayerMappedLinuxComponents>> ScanLinuxAsync(string
$"Scan failed with exit info: {stdout}{Environment.NewLine}{stderr}");
}

var layerDictionary = dockerLayers.ToDictionary(
layer => layer.DiffId,
layer => new List<LinuxComponent>());

var layerDictionary = dockerLayers
.DistinctBy(layer => layer.DiffId)
.ToDictionary(
layer => layer.DiffId,
_ => new List<LinuxComponent>());

try
{
var syftOutput = JsonConvert.DeserializeObject<SyftOutput>(stdout);
Expand Down

0 comments on commit 9605418

Please sign in to comment.