fix issue in IOUtils.toByteArrayWithMaxLength

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898861 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-03-11 21:24:51 +00:00
parent e7f9cd277d
commit f4bfcaeec9
3 changed files with 3 additions and 7 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;