You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2019/12/03 01:52:10 UTC

[tika] 02/03: TIKA-2630 -- add defensive null check and fix "if (...width)" to "if (...height)"

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch branch_1x
in repository https://gitbox.apache.org/repos/asf/tika.git

commit 4eb73d02888fa36d00305f47d3c70f8d9f3d9b48
Author: tallison <ta...@apache.org>
AuthorDate: Mon Dec 2 20:34:51 2019 -0500

    TIKA-2630 -- add defensive null check and fix "if (...width)" to "if (...height)"
---
 .../tika/parser/image/ImageMetadataExtractor.java       | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/image/ImageMetadataExtractor.java b/tika-parsers/src/main/java/org/apache/tika/parser/image/ImageMetadataExtractor.java
index 9fec322..912c0f1 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/image/ImageMetadataExtractor.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/image/ImageMetadataExtractor.java
@@ -504,12 +504,19 @@ public class ImageMetadataExtractor {
 
             // 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));
+                }
             }
 
         }