From f4bfcaeec9c08e1a6ef7bf3ffcb8c3085dd92b7b Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 11 Mar 2022 21:24:51 +0000 Subject: [PATCH] fix issue in IOUtils.toByteArrayWithMaxLength git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898861 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/poi/xwpf/usermodel/XWPFChart.java | 4 +--- .../java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java | 4 +--- poi/src/main/java/org/apache/poi/util/IOUtils.java | 2 +- 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;