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 2020/03/06 21:07:54 UTC

[tika] 01/04: TIKA-3059 -- prevent NPE in new inline image processing code copied from PDFBox

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 f9e64bc9ef95aa1d2f9e9b334fdccfefc94c523b
Author: tallison <ta...@apache.org>
AuthorDate: Fri Mar 6 10:36:08 2020 -0500

    TIKA-3059 -- prevent NPE in new inline image processing code copied from PDFBox
---
 .../tika/parser/pdf/ImageGraphicsEngine.java       | 30 ++++++++++++----------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/pdf/ImageGraphicsEngine.java b/tika-parsers/src/main/java/org/apache/tika/parser/pdf/ImageGraphicsEngine.java
index f47ae73..3f0c9d0 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/pdf/ImageGraphicsEngine.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/pdf/ImageGraphicsEngine.java
@@ -33,6 +33,7 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
 import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
 import org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern;
 import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;
+import org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState;
 import org.apache.pdfbox.pdmodel.graphics.state.PDSoftMask;
 import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
 import org.apache.pdfbox.tools.imageio.ImageIOUtil;
@@ -118,20 +119,23 @@ class ImageGraphicsEngine extends PDFGraphicsStreamEngine {
         }
 
         for (COSName name : res.getExtGStateNames()) {
-            PDSoftMask softMask = res.getExtGState(name).getSoftMask();
-
-            if (softMask != null) {
-                try {
-                    PDTransparencyGroup group = softMask.getGroup();
-
-                    if (group != null) {
-                        // PDFBOX-4327: without this line NPEs will occur
-                        res.getExtGState(name).copyIntoGraphicsState(getGraphicsState());
-
-                        processSoftMask(group);
+            PDExtendedGraphicsState extendedGraphicsState = res.getExtGState(name);
+            if (extendedGraphicsState != null) {
+                PDSoftMask softMask = extendedGraphicsState.getSoftMask();
+
+                if (softMask != null) {
+                    try {
+                        PDTransparencyGroup group = softMask.getGroup();
+
+                        if (group != null) {
+                            // PDFBOX-4327: without this line NPEs will occur
+                            res.getExtGState(name).copyIntoGraphicsState(getGraphicsState());
+
+                            processSoftMask(group);
+                        }
+                    } catch (IOException e) {
+                        handleCatchableIOE(e);
                     }
-                } catch (IOException e) {
-                    handleCatchableIOE(e);
                 }
             }
         }