From 48526517cd8f4d4e99fa90a18e89510e61227fa7 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 7 Apr 2017 06:38:23 +0000 Subject: [PATCH] Adjust checking for Zip-Bomb errors so it also works on JDK >= 8 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1790508 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/openxml4j/opc/TestPackage.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java index f537f139f2..4362f62d14 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java @@ -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; } -- 2.39.5