From 572bfd44f75b5040ffcf9db7df93cb4f8cf5bce2 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Wed, 29 Sep 2021 20:00:36 -0400 Subject: [PATCH] 8062 fix container summary NPE --- .../datamodel/ContainerSummary.java | 30 ++++++------- .../datasourcesummary/ui/ContainerPanel.java | 8 +++- .../ExportContainerInfo.java | 45 ++++++++++++------- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/ContainerSummary.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/ContainerSummary.java index 4ecacdb059..dee05b95f2 100755 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/ContainerSummary.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/ContainerSummary.java @@ -22,10 +22,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; -import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.datasourcesummary.datamodel.SleuthkitCaseProvider.SleuthkitCaseProviderException; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.DataSource; @@ -55,7 +53,7 @@ public class ContainerSummary { public ContainerSummary(SleuthkitCaseProvider provider) { this.provider = provider; } - + /** * Gets the size of unallocated files in a particular datasource. * @@ -151,9 +149,9 @@ public class ContainerSummary { * Generates a string which is a concatenation of the value received from * the result set. * - * @param query The query. - * @param valueParam The parameter for the value in the result set. - * @param separator The string separator used in concatenation. + * @param query The query. + * @param valueParam The parameter for the value in the result set. + * @param separator The string separator used in concatenation. * * @return The concatenated string or null if the query could not be * executed. @@ -212,13 +210,13 @@ public class ContainerSummary { String separator = ", "; return getConcattedStringsResult(query, valueParam, separator); } - + /** * Data model data for data source images. */ public static class ImageDetails { - private final long unallocatedSize; + private final Long unallocatedSize; private final long size; private final long sectorSize; @@ -233,7 +231,8 @@ public class ContainerSummary { /** * Main constructor. * - * @param unallocatedSize Size in bytes of unallocated space. + * @param unallocatedSize Size in bytes of unallocated space or null if + * no unallocated space could be determined. * @param size Total size in bytes. * @param sectorSize Sector size in bytes. * @param timeZone The time zone. @@ -243,7 +242,7 @@ public class ContainerSummary { * @param sha1Hash The sha1 hash or null. * @param sha256Hash The sha256 hash or null. */ - ImageDetails(long unallocatedSize, long size, long sectorSize, + ImageDetails(Long unallocatedSize, long size, long sectorSize, String timeZone, String imageType, List paths, String md5Hash, String sha1Hash, String sha256Hash) { this.unallocatedSize = unallocatedSize; @@ -258,9 +257,10 @@ public class ContainerSummary { } /** - * @return Size in bytes of unallocated space. + * @return Size in bytes of unallocated space or null if no unallocated + * space could be determined. */ - public long getUnallocatedSize() { + public Long getUnallocatedSize() { return unallocatedSize; } @@ -426,8 +426,8 @@ public class ContainerSummary { Long unallocSize = getSizeOfUnallocatedFiles(image); String imageType = image.getType().getName(); - Long size = image.getSize(); - Long sectorSize = image.getSsize(); + long size = image.getSize(); + long sectorSize = image.getSsize(); String timeZone = image.getTimeZone(); List paths = image.getPaths() == null ? Collections.emptyList() : Arrays.asList(image.getPaths()); String md5 = image.getMd5(); diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/ContainerPanel.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/ContainerPanel.java index 9278b3e349..7723b19b12 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/ContainerPanel.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/ContainerPanel.java @@ -174,7 +174,13 @@ class ContainerPanel extends BaseDataSourceSummaryPanel { * @param viewModel The image view model data. */ private void setFieldsForImage(ImageDetails viewModel) { - unallocatedSizeValue.setText(SizeRepresentationUtil.getSizeString(viewModel.getUnallocatedSize())); + Long unallocatedSize = viewModel.getUnallocatedSize(); + if (unallocatedSize == null) { + unallocatedSizeValue.setText(Bundle.ContainerPanel_setFieldsForNonImageDataSource_na()); + } else { + unallocatedSizeValue.setText(SizeRepresentationUtil.getSizeString(unallocatedSize)); + } + imageTypeValue.setText(viewModel.getImageType()); sizeValue.setText(SizeRepresentationUtil.getSizeString(viewModel.getSize())); sectorSizeValue.setText(SizeRepresentationUtil.getSizeString(viewModel.getSectorSize())); diff --git a/Core/src/org/sleuthkit/autopsy/report/modules/datasourcesummaryexport/ExportContainerInfo.java b/Core/src/org/sleuthkit/autopsy/report/modules/datasourcesummaryexport/ExportContainerInfo.java index 44ede9064c..a45301b2d6 100755 --- a/Core/src/org/sleuthkit/autopsy/report/modules/datasourcesummaryexport/ExportContainerInfo.java +++ b/Core/src/org/sleuthkit/autopsy/report/modules/datasourcesummaryexport/ExportContainerInfo.java @@ -40,7 +40,7 @@ import org.sleuthkit.datamodel.DataSource; * Class to export additional details associated with a specific DataSource */ class ExportContainerInfo { - + private final ContainerSummary containerSummary; /** @@ -55,8 +55,9 @@ class ExportContainerInfo { * separate cells in an excel export. * * @param acquisitionDetails The acquisition details. + * * @return The list of key value pairs that can be incorporated into the - * excel export. + * excel export. */ private static List getAcquisitionDetails(String acquisitionDetails) { if (StringUtils.isBlank(acquisitionDetails)) { @@ -105,26 +106,38 @@ class ExportContainerInfo { DefaultCellModel md5 = hasImage ? new DefaultCellModel<>(imageDetails.getMd5Hash()) : NACell; DefaultCellModel sha1 = hasImage ? new DefaultCellModel<>(imageDetails.getSha1Hash()) : NACell; DefaultCellModel sha256 = hasImage ? new DefaultCellModel<>(imageDetails.getSha256Hash()) : NACell; - DefaultCellModel unallocatedSize = hasImage ? SizeRepresentationUtil.getBytesCell(imageDetails.getUnallocatedSize()) : NACell; + + DefaultCellModel unallocatedSize; + if (hasImage) { + Long unallocatedSizeVal = imageDetails.getUnallocatedSize(); + if (unallocatedSizeVal != null) { + unallocatedSize = SizeRepresentationUtil.getBytesCell(unallocatedSizeVal); + } else { + unallocatedSize = NACell; + } + } else { + unallocatedSize = NACell; + } + List paths = containerDetails.getImageDetails() == null ? Collections.singletonList(NA) : containerDetails.getImageDetails().getPaths(); List cellPaths = paths.stream() .map(SingleCellExportable::new) .collect(Collectors.toList()); return Arrays.asList(new ExcelSpecialFormatExport(Bundle.ExportContainerInfo_tabName(), Arrays.asList(new KeyValueItemExportable(Bundle.ExportContainerInfo_export_displayName(), new DefaultCellModel<>(containerDetails.getDisplayName())), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_originalName(), new DefaultCellModel<>(containerDetails.getOriginalName())), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_deviceId(), new DefaultCellModel<>(containerDetails.getDeviceId())), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_timeZone(), timeZone), - new TitledExportable(Bundle.ExportContainerInfo_export_acquisitionDetails(), getAcquisitionDetails(containerDetails.getAcquisitionDetails())), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_imageType(), imageType), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_size(), size), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sectorSize(), sectorSize), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_md5(), md5), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha1(), sha1), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha256(), sha256), - new KeyValueItemExportable(Bundle.ExportContainerInfo_export_unallocatedSize(), unallocatedSize), - new TitledExportable(Bundle.ExportContainerInfo_export_filePaths(), cellPaths) - ))); + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_originalName(), new DefaultCellModel<>(containerDetails.getOriginalName())), + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_deviceId(), new DefaultCellModel<>(containerDetails.getDeviceId())), + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_timeZone(), timeZone), + new TitledExportable(Bundle.ExportContainerInfo_export_acquisitionDetails(), getAcquisitionDetails(containerDetails.getAcquisitionDetails())), + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_imageType(), imageType), + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_size(), size), + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sectorSize(), sectorSize), + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_md5(), md5), + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha1(), sha1), + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha256(), sha256), + new KeyValueItemExportable(Bundle.ExportContainerInfo_export_unallocatedSize(), unallocatedSize), + new TitledExportable(Bundle.ExportContainerInfo_export_filePaths(), cellPaths) + ))); } }