From: PJ Fanning Date: Fri, 8 Oct 2021 23:56:30 +0000 (+0000) Subject: remove text size limit X-Git-Tag: REL_5_2_0~422 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f69682ef8c3124f1476bb5f25c31b5ce8f9df106;p=poi.git remove text size limit git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894051 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipSecureFile.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipSecureFile.java index e9365b4a74..f91674bcae 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipSecureFile.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipSecureFile.java @@ -80,7 +80,7 @@ public class ZipSecureFile extends ZipFile { if (maxEntrySize < 0) { throw new IllegalArgumentException("Max entry size must be greater than or equal to zero"); } else if (maxEntrySize > 0xFFFFFFFFL) { - LOG.atWarn().log("setting max entry size greater tahn 4Gb can be risky; set to " + maxEntrySize + " bytes"); + LOG.atWarn().log("setting max entry size greater than 4Gb can be risky; set to " + maxEntrySize + " bytes"); } MAX_ENTRY_SIZE = maxEntrySize; } @@ -105,10 +105,13 @@ public class ZipSecureFile extends ZipFile { * security vulnerabilities when documents are provided by users. * * @param maxTextSize the max. file size of a single zip entry + * @throws IllegalArgumentException for negative maxTextSize */ public static void setMaxTextSize(long maxTextSize) { - if (maxTextSize < 0 || maxTextSize > 0xFFFFFFFFL) { // don't use MAX_ENTRY_SIZE here! - throw new IllegalArgumentException("Max text size is bounded [0-4GB], but had " + maxTextSize); + if (maxTextSize < 0) { + throw new IllegalArgumentException("Max text size must be greater than or equal to zero"); + }else if (maxTextSize > 0xFFFFFFFFL) { + LOG.atWarn().log("setting max text size greater than " + 0xFFFFFFFFL + " can be risky; set to " + maxTextSize + " chars"); } MAX_TEXT_SIZE = maxTextSize; } @@ -116,9 +119,8 @@ public class ZipSecureFile extends ZipFile { /** * Returns the current maximum allowed text size. * - * See setMaxTextSize() for details. - * - * @return The max accepted text size. + * @return The max accepted text size. + * @see #setMaxTextSize(long) */ public static long getMaxTextSize() { return MAX_TEXT_SIZE; diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/util/TestZipSecureFile.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/util/TestZipSecureFile.java index 2eef717dfa..e14bd87fcd 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/util/TestZipSecureFile.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/util/TestZipSecureFile.java @@ -63,4 +63,20 @@ class TestZipSecureFile { ZipSecureFile.setMaxEntrySize(0xFFFFFFFFL); } } + + @Test + void testSettingMaxTextSizeAsNegative() { + assertThrows(IllegalArgumentException.class, () -> ZipSecureFile.setMaxTextSize(-1)); + } + + @Test + void testSettingMaxTextSizeAs8GChars() { + long approx8G = 0xFFFFFFFFL * 2; + try { + ZipSecureFile.setMaxTextSize(approx8G); + assertEquals(approx8G, ZipSecureFile.getMaxTextSize()); + } finally { + ZipSecureFile.setMaxTextSize(0xFFFFFFFFL); + } + } }