From 46ef84d40b6026c1712a11850a44745fdb453e1f Mon Sep 17 00:00:00 2001 From: "U-BASIS\\dsmyda" Date: Thu, 15 Oct 2020 17:00:14 -0400 Subject: [PATCH 1/3] Fixed the nightly tiff bug by adding a consistent ordering to the image providers of ImageIO --- .../autopsy/ingest/IngestManager.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java b/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java index 95696378b7..3600108a0a 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java @@ -30,6 +30,7 @@ import java.util.Date; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -45,6 +46,8 @@ import java.util.stream.Stream; import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.ThreadSafe; +import javax.imageio.ImageIO; +import javax.imageio.spi.IIORegistry; import javax.swing.JOptionPane; import org.netbeans.api.progress.ProgressHandle; import org.openide.util.Cancellable; @@ -395,6 +398,13 @@ public class IngestManager implements IngestProgressSnapshotProvider { "IngestManager.startupErr.dlgErrorList=Errors:" }) IngestJobStartResult startIngestJob(IngestJob job) { + /** + * Initialize Java's Image I/O API so that modules processing + * image files will consistently get the same image readers and writers. + * See JIRA-6951 for more details. + */ + initializeImageIO(); + List errors = null; Case openCase; try { @@ -887,6 +897,44 @@ public class IngestManager implements IngestProgressSnapshotProvider { } } + /** + * Initializes the ImageIO API and sorts the providers for + * deterministic image reading and writing. + */ + private void initializeImageIO() { + ImageIO.scanForPlugins(); + + // Sift through each registry category and sort category providers by + // their canonical class name. + IIORegistry pluginRegistry = IIORegistry.getDefaultInstance(); + Iterator> categories = pluginRegistry.getCategories(); + while(categories.hasNext()) { + sortPluginsInCategory(pluginRegistry, categories.next()); + } + } + + /** + * Sorts all ImageIO SPI providers by their class name. + */ + private void sortPluginsInCategory(IIORegistry pluginRegistry, Class category) { + Iterator serviceProviderIter = pluginRegistry.getServiceProviders(category, false); + ArrayList providers = new ArrayList<>(); + while (serviceProviderIter.hasNext()) { + providers.add(serviceProviderIter.next()); + } + Collections.sort(providers, (first, second) -> { + return first.getClass().getCanonicalName().compareToIgnoreCase(second.getClass().getCanonicalName()); + }); + for(int i = 0; i < providers.size(); i++) { + for(int j = i + 1; j < providers.size(); j++) { + // The registry only accepts pairwise orderings. To guarentee a + // total order, all pairs need to be exhausted. + pluginRegistry.setOrdering(category, providers.get(i), + providers.get(j)); + } + } + } + /** * Creates and starts an ingest job for a collection of data sources. */ From 67dc05956dfb1821184dcbd43d5e890dd826830b Mon Sep 17 00:00:00 2001 From: "U-BASIS\\dsmyda" Date: Fri, 16 Oct 2020 14:32:24 -0400 Subject: [PATCH 2/3] Removed the init code from ingest and added it to the embedded file extractors start up code --- .../autopsy/ingest/IngestManager.java | 45 ----------------- .../EmbeddedFileExtractorIngestModule.java | 50 +++++++++++++++++++ 2 files changed, 50 insertions(+), 45 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java b/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java index 3600108a0a..8dc04f9f56 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java @@ -398,13 +398,6 @@ public class IngestManager implements IngestProgressSnapshotProvider { "IngestManager.startupErr.dlgErrorList=Errors:" }) IngestJobStartResult startIngestJob(IngestJob job) { - /** - * Initialize Java's Image I/O API so that modules processing - * image files will consistently get the same image readers and writers. - * See JIRA-6951 for more details. - */ - initializeImageIO(); - List errors = null; Case openCase; try { @@ -897,44 +890,6 @@ public class IngestManager implements IngestProgressSnapshotProvider { } } - /** - * Initializes the ImageIO API and sorts the providers for - * deterministic image reading and writing. - */ - private void initializeImageIO() { - ImageIO.scanForPlugins(); - - // Sift through each registry category and sort category providers by - // their canonical class name. - IIORegistry pluginRegistry = IIORegistry.getDefaultInstance(); - Iterator> categories = pluginRegistry.getCategories(); - while(categories.hasNext()) { - sortPluginsInCategory(pluginRegistry, categories.next()); - } - } - - /** - * Sorts all ImageIO SPI providers by their class name. - */ - private void sortPluginsInCategory(IIORegistry pluginRegistry, Class category) { - Iterator serviceProviderIter = pluginRegistry.getServiceProviders(category, false); - ArrayList providers = new ArrayList<>(); - while (serviceProviderIter.hasNext()) { - providers.add(serviceProviderIter.next()); - } - Collections.sort(providers, (first, second) -> { - return first.getClass().getCanonicalName().compareToIgnoreCase(second.getClass().getCanonicalName()); - }); - for(int i = 0; i < providers.size(); i++) { - for(int j = i + 1; j < providers.size(); j++) { - // The registry only accepts pairwise orderings. To guarentee a - // total order, all pairs need to be exhausted. - pluginRegistry.setOrdering(category, providers.get(i), - providers.get(j)); - } - } - } - /** * Creates and starts an ingest job for a collection of data sources. */ diff --git a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/EmbeddedFileExtractorIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/EmbeddedFileExtractorIngestModule.java index fd833b59a7..dc9e7c6d1d 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/EmbeddedFileExtractorIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/embeddedfileextractor/EmbeddedFileExtractorIngestModule.java @@ -20,7 +20,12 @@ package org.sleuthkit.autopsy.modules.embeddedfileextractor; import java.io.File; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; +import javax.imageio.ImageIO; +import javax.imageio.spi.IIORegistry; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.AbstractFile; @@ -122,8 +127,53 @@ public final class EmbeddedFileExtractorIngestModule extends FileIngestModuleAda } catch (NoCurrentCaseException ex) { throw new IngestModuleException(Bundle.EmbeddedFileExtractorIngestModule_UnableToGetMSOfficeExtractor_errMsg(), ex); } + + /** + * Initialize Java's Image I/O API so that image reading and writing + * (needed for image extraction) happens consistently through the + * same providers. See JIRA-6951 for more details. + */ + initializeImageIO(); } + + /** + * Initializes the ImageIO API and sorts the providers for + * deterministic image reading and writing. + */ + private void initializeImageIO() { + ImageIO.scanForPlugins(); + + // Sift through each registry category and sort category providers by + // their canonical class name. + IIORegistry pluginRegistry = IIORegistry.getDefaultInstance(); + Iterator> categories = pluginRegistry.getCategories(); + while(categories.hasNext()) { + sortPluginsInCategory(pluginRegistry, categories.next()); + } + } + + /** + * Sorts all ImageIO SPI providers by their class name. + */ + private void sortPluginsInCategory(IIORegistry pluginRegistry, Class category) { + Iterator serviceProviderIter = pluginRegistry.getServiceProviders(category, false); + ArrayList providers = new ArrayList<>(); + while (serviceProviderIter.hasNext()) { + providers.add(serviceProviderIter.next()); + } + Collections.sort(providers, (first, second) -> { + return first.getClass().getCanonicalName().compareToIgnoreCase(second.getClass().getCanonicalName()); + }); + for(int i = 0; i < providers.size() - 1; i++) { + for(int j = i + 1; j < providers.size(); j++) { + // The registry only accepts pairwise orderings. To guarantee a + // total order, all pairs need to be exhausted. + pluginRegistry.setOrdering(category, providers.get(i), + providers.get(j)); + } + } + } @Override public ProcessResult process(AbstractFile abstractFile) { From 600585ebab44734c68225cc7fbd529b3dc1caa2b Mon Sep 17 00:00:00 2001 From: "U-BASIS\\dsmyda" Date: Fri, 16 Oct 2020 14:33:26 -0400 Subject: [PATCH 3/3] Removed unused imports --- Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java b/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java index 8dc04f9f56..95696378b7 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/IngestManager.java @@ -30,7 +30,6 @@ import java.util.Date; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -46,8 +45,6 @@ import java.util.stream.Stream; import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.ThreadSafe; -import javax.imageio.ImageIO; -import javax.imageio.spi.IIORegistry; import javax.swing.JOptionPane; import org.netbeans.api.progress.ProgressHandle; import org.openide.util.Cancellable;