From 5bc2657704271a40fb218cc25783c9a5ef4cda83 Mon Sep 17 00:00:00 2001 From: Coby Allred Date: Tue, 8 Feb 2022 16:52:20 -0800 Subject: [PATCH] Handle duplicate DiffId docker image layers --- .../linux/LinuxContainerDetector.cs | 2 ++ .../linux/LinuxScanner.cs | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs index e5466d9e6..62a4eefdf 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs @@ -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(), @@ -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(), diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs index 8d0544419..80951c6a3 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs @@ -90,10 +90,12 @@ public async Task> ScanLinuxAsync(string $"Scan failed with exit info: {stdout}{Environment.NewLine}{stderr}"); } - var layerDictionary = dockerLayers.ToDictionary( - layer => layer.DiffId, - layer => new List()); - + var layerDictionary = dockerLayers + .DistinctBy(layer => layer.DiffId) + .ToDictionary( + layer => layer.DiffId, + _ => new List()); + try { var syftOutput = JsonConvert.DeserializeObject(stdout);