diff options
author | Maxim Valyanskiy <maxcom@apache.org> | 2011-05-18 10:38:08 +0000 |
---|---|---|
committer | Maxim Valyanskiy <maxcom@apache.org> | 2011-05-18 10:38:08 +0000 |
commit | d399e2ad567517336439bb92271818000a47ed57 (patch) | |
tree | c8483889b1949c15833193831d9d9f46a70c9ed8 /src/ooxml | |
parent | 3f11efa41cc245d7ad627f6700152a57d1fdfcb3 (diff) | |
download | poi-d399e2ad567517336439bb92271818000a47ed57.tar.gz poi-d399e2ad567517336439bb92271818000a47ed57.zip |
FakeZipEntry: pre-allocate ByteArrayOutputStream when zip entry size is known to prevent reallocation
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1124179 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r-- | src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java index 0b9822eab1..45674f897e 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java @@ -108,7 +108,20 @@ public class ZipInputStreamZipEntrySource implements ZipEntrySource { super(entry.getName()); // Grab the de-compressed contents for later - ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ByteArrayOutputStream baos; + + long entrySize = entry.getSize(); + + if (entrySize !=-1) { + if (entrySize>=Integer.MAX_VALUE) { + throw new IOException("ZIP entry size is too large"); + } + + baos = new ByteArrayOutputStream((int) entrySize); + } else { + baos = new ByteArrayOutputStream(); + } + byte[] buffer = new byte[4096]; int read = 0; while( (read = inp.read(buffer)) != -1 ) { |