aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-03-11 21:24:51 +0000
committerPJ Fanning <fanningpj@apache.org>2022-03-11 21:24:51 +0000
commitf4bfcaeec9c08e1a6ef7bf3ffcb8c3085dd92b7b (patch)
tree3bc73f49f2226a8f85ec31335c0df845b3fe4691
parente7f9cd277d400e1a726d4b5acfe5c9ddf21a4eee (diff)
downloadpoi-f4bfcaeec9c08e1a6ef7bf3ffcb8c3085dd92b7b.tar.gz
poi-f4bfcaeec9c08e1a6ef7bf3ffcb8c3085dd92b7b.zip
fix issue in IOUtils.toByteArrayWithMaxLength
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898861 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java4
-rw-r--r--poi/src/main/java/org/apache/poi/util/IOUtils.java2
3 files changed, 3 insertions, 7 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java
index 718e036807..4eca490526 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java
@@ -92,13 +92,11 @@ public class XWPFChart extends XDDFChart {
public Long getChecksum() {
if (this.checksum == null) {
- byte[] data;
try (InputStream is = getPackagePart().getInputStream()) {
- data = IOUtils.toByteArrayWithMaxLength(is, XWPFPictureData.getMaxImageSize());
+ this.checksum = IOUtils.calculateChecksum(is);
} catch (IOException e) {
throw new POIXMLException(e);
}
- this.checksum = IOUtils.calculateChecksum(data);
}
return this.checksum;
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
index a4a84021ed..4e4ad700ca 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
@@ -163,13 +163,11 @@ public class XWPFPictureData extends POIXMLDocumentPart {
public Long getChecksum() {
if (this.checksum == null) {
- byte[] data;
try (InputStream is = getPackagePart().getInputStream()) {
- data = IOUtils.toByteArrayWithMaxLength(is, getMaxImageSize());
+ this.checksum = IOUtils.calculateChecksum(is);
} catch (IOException e) {
throw new POIXMLException(e);
}
- this.checksum = IOUtils.calculateChecksum(data);
}
return this.checksum;
}
diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java b/poi/src/main/java/org/apache/poi/util/IOUtils.java
index 37ad46846f..f0dbc1aa99 100644
--- a/poi/src/main/java/org/apache/poi/util/IOUtils.java
+++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java
@@ -202,7 +202,7 @@ public final class IOUtils {
}
final int derivedLen = Math.min(length, derivedMaxLength);
- final int bufferLen = isLengthKnown ? derivedLen : 4096;
+ final int bufferLen = isLengthKnown ? derivedLen : Math.min(4096, derivedLen);
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(bufferLen)) {
byte[] buffer = new byte[4096];
int totalBytes = 0, readBytes;