8062 fix container summary NPE

This commit is contained in:
Greg DiCristofaro 2021-09-29 20:00:36 -04:00
parent cc51e9d095
commit 572bfd44f7
3 changed files with 51 additions and 32 deletions

View File

@ -22,10 +22,8 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import org.sleuthkit.autopsy.datasourcesummary.datamodel.SleuthkitCaseProvider.SleuthkitCaseProviderException;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.DataSource; import org.sleuthkit.datamodel.DataSource;
@ -55,7 +53,7 @@ public class ContainerSummary {
public ContainerSummary(SleuthkitCaseProvider provider) { public ContainerSummary(SleuthkitCaseProvider provider) {
this.provider = provider; this.provider = provider;
} }
/** /**
* Gets the size of unallocated files in a particular datasource. * 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 * Generates a string which is a concatenation of the value received from
* the result set. * the result set.
* *
* @param query The query. * @param query The query.
* @param valueParam The parameter for the value in the result set. * @param valueParam The parameter for the value in the result set.
* @param separator The string separator used in concatenation. * @param separator The string separator used in concatenation.
* *
* @return The concatenated string or null if the query could not be * @return The concatenated string or null if the query could not be
* executed. * executed.
@ -212,13 +210,13 @@ public class ContainerSummary {
String separator = ", "; String separator = ", ";
return getConcattedStringsResult(query, valueParam, separator); return getConcattedStringsResult(query, valueParam, separator);
} }
/** /**
* Data model data for data source images. * Data model data for data source images.
*/ */
public static class ImageDetails { public static class ImageDetails {
private final long unallocatedSize; private final Long unallocatedSize;
private final long size; private final long size;
private final long sectorSize; private final long sectorSize;
@ -233,7 +231,8 @@ public class ContainerSummary {
/** /**
* Main constructor. * 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 size Total size in bytes.
* @param sectorSize Sector size in bytes. * @param sectorSize Sector size in bytes.
* @param timeZone The time zone. * @param timeZone The time zone.
@ -243,7 +242,7 @@ public class ContainerSummary {
* @param sha1Hash The sha1 hash or null. * @param sha1Hash The sha1 hash or null.
* @param sha256Hash The sha256 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<String> paths, String md5Hash, String timeZone, String imageType, List<String> paths, String md5Hash,
String sha1Hash, String sha256Hash) { String sha1Hash, String sha256Hash) {
this.unallocatedSize = unallocatedSize; 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; return unallocatedSize;
} }
@ -426,8 +426,8 @@ public class ContainerSummary {
Long unallocSize = getSizeOfUnallocatedFiles(image); Long unallocSize = getSizeOfUnallocatedFiles(image);
String imageType = image.getType().getName(); String imageType = image.getType().getName();
Long size = image.getSize(); long size = image.getSize();
Long sectorSize = image.getSsize(); long sectorSize = image.getSsize();
String timeZone = image.getTimeZone(); String timeZone = image.getTimeZone();
List<String> paths = image.getPaths() == null ? Collections.emptyList() : Arrays.asList(image.getPaths()); List<String> paths = image.getPaths() == null ? Collections.emptyList() : Arrays.asList(image.getPaths());
String md5 = image.getMd5(); String md5 = image.getMd5();

View File

@ -174,7 +174,13 @@ class ContainerPanel extends BaseDataSourceSummaryPanel {
* @param viewModel The image view model data. * @param viewModel The image view model data.
*/ */
private void setFieldsForImage(ImageDetails viewModel) { 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()); imageTypeValue.setText(viewModel.getImageType());
sizeValue.setText(SizeRepresentationUtil.getSizeString(viewModel.getSize())); sizeValue.setText(SizeRepresentationUtil.getSizeString(viewModel.getSize()));
sectorSizeValue.setText(SizeRepresentationUtil.getSizeString(viewModel.getSectorSize())); sectorSizeValue.setText(SizeRepresentationUtil.getSizeString(viewModel.getSectorSize()));

View File

@ -40,7 +40,7 @@ import org.sleuthkit.datamodel.DataSource;
* Class to export additional details associated with a specific DataSource * Class to export additional details associated with a specific DataSource
*/ */
class ExportContainerInfo { class ExportContainerInfo {
private final ContainerSummary containerSummary; private final ContainerSummary containerSummary;
/** /**
@ -55,8 +55,9 @@ class ExportContainerInfo {
* separate cells in an excel export. * separate cells in an excel export.
* *
* @param acquisitionDetails The acquisition details. * @param acquisitionDetails The acquisition details.
*
* @return The list of key value pairs that can be incorporated into the * @return The list of key value pairs that can be incorporated into the
* excel export. * excel export.
*/ */
private static List<? extends ExcelItemExportable> getAcquisitionDetails(String acquisitionDetails) { private static List<? extends ExcelItemExportable> getAcquisitionDetails(String acquisitionDetails) {
if (StringUtils.isBlank(acquisitionDetails)) { if (StringUtils.isBlank(acquisitionDetails)) {
@ -105,26 +106,38 @@ class ExportContainerInfo {
DefaultCellModel<?> md5 = hasImage ? new DefaultCellModel<>(imageDetails.getMd5Hash()) : NACell; DefaultCellModel<?> md5 = hasImage ? new DefaultCellModel<>(imageDetails.getMd5Hash()) : NACell;
DefaultCellModel<?> sha1 = hasImage ? new DefaultCellModel<>(imageDetails.getSha1Hash()) : NACell; DefaultCellModel<?> sha1 = hasImage ? new DefaultCellModel<>(imageDetails.getSha1Hash()) : NACell;
DefaultCellModel<?> sha256 = hasImage ? new DefaultCellModel<>(imageDetails.getSha256Hash()) : 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<String> paths = containerDetails.getImageDetails() == null ? Collections.singletonList(NA) : containerDetails.getImageDetails().getPaths(); List<String> paths = containerDetails.getImageDetails() == null ? Collections.singletonList(NA) : containerDetails.getImageDetails().getPaths();
List<SingleCellExportable> cellPaths = paths.stream() List<SingleCellExportable> cellPaths = paths.stream()
.map(SingleCellExportable::new) .map(SingleCellExportable::new)
.collect(Collectors.toList()); .collect(Collectors.toList());
return Arrays.asList(new ExcelSpecialFormatExport(Bundle.ExportContainerInfo_tabName(), Arrays.asList(new KeyValueItemExportable(Bundle.ExportContainerInfo_export_displayName(), new DefaultCellModel<>(containerDetails.getDisplayName())), 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_originalName(), new DefaultCellModel<>(containerDetails.getOriginalName())),
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_deviceId(), new DefaultCellModel<>(containerDetails.getDeviceId())), new KeyValueItemExportable(Bundle.ExportContainerInfo_export_deviceId(), new DefaultCellModel<>(containerDetails.getDeviceId())),
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_timeZone(), timeZone), new KeyValueItemExportable(Bundle.ExportContainerInfo_export_timeZone(), timeZone),
new TitledExportable(Bundle.ExportContainerInfo_export_acquisitionDetails(), getAcquisitionDetails(containerDetails.getAcquisitionDetails())), new TitledExportable(Bundle.ExportContainerInfo_export_acquisitionDetails(), getAcquisitionDetails(containerDetails.getAcquisitionDetails())),
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_imageType(), imageType), new KeyValueItemExportable(Bundle.ExportContainerInfo_export_imageType(), imageType),
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_size(), size), new KeyValueItemExportable(Bundle.ExportContainerInfo_export_size(), size),
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sectorSize(), sectorSize), new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sectorSize(), sectorSize),
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_md5(), md5), new KeyValueItemExportable(Bundle.ExportContainerInfo_export_md5(), md5),
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha1(), sha1), new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha1(), sha1),
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha256(), sha256), new KeyValueItemExportable(Bundle.ExportContainerInfo_export_sha256(), sha256),
new KeyValueItemExportable(Bundle.ExportContainerInfo_export_unallocatedSize(), unallocatedSize), new KeyValueItemExportable(Bundle.ExportContainerInfo_export_unallocatedSize(), unallocatedSize),
new TitledExportable(Bundle.ExportContainerInfo_export_filePaths(), cellPaths) new TitledExportable(Bundle.ExportContainerInfo_export_filePaths(), cellPaths)
))); )));
} }
} }