]> source.dussan.org Git - poi.git/commitdiff
remove text size limit
authorPJ Fanning <fanningpj@apache.org>
Fri, 8 Oct 2021 23:56:30 +0000 (23:56 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 8 Oct 2021 23:56:30 +0000 (23:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894051 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipSecureFile.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/util/TestZipSecureFile.java

index e9365b4a74ed919d64c25bb88f86377e1afcfcb7..f91674bcae95ca49f79f5f5faf83850d52b4e3a1 100644 (file)
@@ -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;
index 2eef717dfa709faa2d03f7117c9ffc7a467139b9..e14bd87fcd0e36852ef562dc47c32db24c1ccb63 100644 (file)
@@ -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);
+        }
+    }
 }