From 425d45324e8029243e5dbdacb9960425c8a54ed1 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Wed, 20 Sep 2023 16:20:37 -0400 Subject: [PATCH] fail if no provider and no image paths --- .../casemodule/Bundle.properties-MERGED | 3 ++ .../sleuthkit/autopsy/casemodule/Case.java | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties-MERGED index ce1fb9aa70..1f9719688f 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties-MERGED @@ -107,6 +107,9 @@ Case.servicesException.notificationTitle={0} Error Case.servicesException.serviceResourcesCloseError=Could not close case resources for {0} service: {1} Case_caseType_multiUser=Multi-user case Case_caseType_singleUser=Single-user case +Case_checkImagePaths_exceptionOccurred=An exception occurred while checking if image paths are present +# {0} - paths +Case_checkImagePaths_noPaths=The following images had no associated paths: {0} CaseDetailsPanel.casePanel.border.title=Case CaseDetailsPanel.examinerLabel.text=Name: CaseDetailsPanel.examinerPanel.border.title=Examiner diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 2b6eedb092..3f9c440122 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -41,6 +41,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -64,6 +65,7 @@ import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.ThreadSafe; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -2284,6 +2286,8 @@ public class Case { checkForCancellation(); openCommunicationChannels(progressIndicator); checkForCancellation(); + checkImagePaths(); + checkForCancellation(); openFileSystemsInBackground(); return null; @@ -2302,6 +2306,40 @@ public class Case { throw ex; } } + + /** + * Check if content provider is present, all images have paths, or throw an error. + * @throws CaseActionException + */ + @Messages({ + "# {0} - paths", + "Case_checkImagePaths_noPaths=The following images had no associated paths: {0}", + "Case_checkImagePaths_exceptionOccurred=An exception occurred while checking if image paths are present" + }) + private void checkImagePaths() throws CaseActionException { + // if there is a content provider, images don't necessarily need paths + if (StringUtils.isNotBlank(this.metadata.getContentProviderName())) { + return; + } + + // identify images without paths + try { + List noPathImages = new ArrayList<>(); + List images = this.caseDb.getImages(); + for (Image img: images) { + if (ArrayUtils.isEmpty(img.getPaths())) { + noPathImages.add(img); + } + } + + if (!noPathImages.isEmpty()) { + String imageListStr = noPathImages.stream().map(Image::getName).collect(Collectors.joining(", ")); + throw new CaseActionException(Bundle.Case_checkImagePaths_noPaths(imageListStr)); + } + } catch (TskCoreException ex) { + throw new CaseActionException(Bundle.Case_checkImagePaths_exceptionOccurred(), ex); + } + } /** * Starts a background task that reads a sector from each file system of