remove text size limit

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894055 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-10-09 06:55:31 +00:00
parent f69682ef8c
commit 5baa34caf2
2 changed files with 13 additions and 11 deletions

View File

@ -36,10 +36,12 @@ import org.apache.logging.log4j.Logger;
public class ZipSecureFile extends ZipFile {
private static final Logger LOG = LogManager.getLogger(ZipSecureFile.class);
/* package */ static double MIN_INFLATE_RATIO = 0.01d;
/* package */ static long MAX_ENTRY_SIZE = 0xFFFFFFFFL;
// The default maximum size of extracted text
private static long MAX_TEXT_SIZE = 10*1024*1024L;
/* package */ static final long DEFAULT_MAX_ENTRY_SIZE = 0xFFFFFFFFL;
/* package */ static long MAX_ENTRY_SIZE = DEFAULT_MAX_ENTRY_SIZE;
// The maximum chars of extracted text
/* package */ static final long DEFAULT_MAX_TEXT_SIZE = 10*1024*1024L;
private static long MAX_TEXT_SIZE = DEFAULT_MAX_TEXT_SIZE;
private final String fileName;
@ -79,7 +81,7 @@ public class ZipSecureFile extends ZipFile {
public static void setMaxEntrySize(long maxEntrySize) {
if (maxEntrySize < 0) {
throw new IllegalArgumentException("Max entry size must be greater than or equal to zero");
} else if (maxEntrySize > 0xFFFFFFFFL) {
} else if (maxEntrySize > DEFAULT_MAX_ENTRY_SIZE) {
LOG.atWarn().log("setting max entry size greater than 4Gb can be risky; set to " + maxEntrySize + " bytes");
}
MAX_ENTRY_SIZE = maxEntrySize;
@ -110,8 +112,8 @@ public class ZipSecureFile extends ZipFile {
public static void setMaxTextSize(long 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");
}else if (maxTextSize > DEFAULT_MAX_TEXT_SIZE) {
LOG.atWarn().log("setting max text size greater than " + DEFAULT_MAX_TEXT_SIZE + " can be risky; set to " + maxTextSize + " chars");
}
MAX_TEXT_SIZE = maxTextSize;
}

View File

@ -55,12 +55,12 @@ class TestZipSecureFile {
@Test
void testSettingMaxEntrySizeAs8Gb() {
long approx8Gb = 0xFFFFFFFFL * 2;
long approx8Gb = ZipSecureFile.MAX_ENTRY_SIZE * 2;
try {
ZipSecureFile.setMaxEntrySize(approx8Gb);
assertEquals(approx8Gb, ZipSecureFile.getMaxEntrySize());
} finally {
ZipSecureFile.setMaxEntrySize(0xFFFFFFFFL);
ZipSecureFile.setMaxEntrySize(ZipSecureFile.MAX_ENTRY_SIZE);
}
}
@ -71,12 +71,12 @@ class TestZipSecureFile {
@Test
void testSettingMaxTextSizeAs8GChars() {
long approx8G = 0xFFFFFFFFL * 2;
long approx8G = ZipSecureFile.MAX_ENTRY_SIZE * 2;
try {
ZipSecureFile.setMaxTextSize(approx8G);
assertEquals(approx8G, ZipSecureFile.getMaxTextSize());
} finally {
ZipSecureFile.setMaxTextSize(0xFFFFFFFFL);
ZipSecureFile.setMaxTextSize(ZipSecureFile.DEFAULT_MAX_TEXT_SIZE);
}
}
}