]> source.dussan.org Git - poi.git/commitdiff
Adjust checking for Zip-Bomb errors so it also works on JDK >= 8
authorDominik Stadler <centic@apache.org>
Fri, 7 Apr 2017 06:38:23 +0000 (06:38 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 7 Apr 2017 06:38:23 +0000 (06:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1790508 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java

index f537f139f2f492e96f0edf4fc263d8b6ac4f7b53..4362f62d14d4425500aacbfeb28399fa1d238557 100644 (file)
@@ -897,18 +897,15 @@ public final class TestPackage {
     }
 
     private void checkForZipBombException(Throwable e) {
+       // unwrap InvocationTargetException as they usually contain the nested exception in the "target" member
         if(e instanceof InvocationTargetException) {
-            InvocationTargetException t = (InvocationTargetException)e;
-            IOException t2 = (IOException)t.getTargetException();
-            if(t2.getMessage().startsWith("Zip bomb detected!") ||
-                                       t2.getMessage().startsWith("The parser has encountered more than \"4,096\" entity expansions in this document;")) {
-                return;
-            }
+                       e = ((InvocationTargetException)e).getTargetException();
         }
         
         String msg = e.getMessage();
         if(msg != null && (msg.startsWith("Zip bomb detected!") ||
-                               msg.startsWith("The parser has encountered more than \"4,096\" entity expansions in this document;"))) {
+                               msg.contains("The parser has encountered more than \"4,096\" entity expansions in this document;") ||
+                               msg.contains("The parser has encountered more than \"4096\" entity expansions in this document;"))) {
             return;
         }