Skip to content

Commit

Permalink
TIKA-2630 -- add defensive null check and fix "if (...width)" to "if …
Browse files Browse the repository at this point in the history
…(...height)"
  • Loading branch information
tballison committed Dec 3, 2019
1 parent 3c3214d commit 4eb73d0
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,19 @@ public void handlePhotoTags(Directory directory, Metadata metadata) {

// For Compressed Images read from ExifSubIFDDirectory
if (directory.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH)) {
metadata.set(Metadata.IMAGE_WIDTH,
trimPixels(directory.getDescription(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH)));
String width = directory.getDescription(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH);
//check for null because this could overwrite earlier set width if the value is null
if (width != null) {
metadata.set(Metadata.IMAGE_WIDTH,
trimPixels(width));
}
}
if (directory.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH)) {
metadata.set(Metadata.IMAGE_LENGTH,
trimPixels(directory.getDescription(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT)));

if (directory.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT)) {
String height = directory.getDescription(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT);
if (height != null) {
metadata.set(Metadata.IMAGE_LENGTH, trimPixels(height));
}
}

}
Expand Down

0 comments on commit 4eb73d0

Please sign in to comment.