git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898237 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_1
@@ -94,7 +94,7 @@ public class XWPFChart extends XDDFChart { | |||
if (this.checksum == null) { | |||
byte[] data; | |||
try (InputStream is = getPackagePart().getInputStream()) { | |||
data = IOUtils.toByteArray(is); | |||
data = IOUtils.toByteArray(is, XWPFPictureData.getMaxImageSize()); | |||
} catch (IOException e) { | |||
throw new POIXMLException(e); | |||
} |
@@ -107,7 +107,7 @@ public class XWPFComments extends POIXMLDocumentPart { | |||
* @throws IOException If reading the picture-data from the stream fails. | |||
*/ | |||
public String addPictureData(InputStream is, int format) throws InvalidFormatException, IOException { | |||
byte[] data = IOUtils.toByteArray(is); | |||
byte[] data = IOUtils.toByteArray(is, XWPFPictureData.getMaxImageSize()); | |||
return addPictureData(data, format); | |||
} | |||
@@ -1520,7 +1520,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { | |||
public String addPictureData(InputStream is, int format) throws InvalidFormatException { | |||
try { | |||
byte[] data = IOUtils.toByteArray(is); | |||
byte[] data = IOUtils.toByteArray(is, XWPFPictureData.getMaxImageSize()); | |||
return addPictureData(data, format); | |||
} catch (IOException e) { | |||
throw new POIXMLException(e); |
@@ -279,7 +279,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo | |||
* @throws IOException If reading the picture-data from the stream fails. | |||
*/ | |||
public String addPictureData(InputStream is, int format) throws InvalidFormatException, IOException { | |||
byte[] data = IOUtils.toByteArray(is); | |||
byte[] data = IOUtils.toByteArray(is, XWPFPictureData.getMaxImageSize()); | |||
return addPictureData(data, format); | |||
} | |||
@@ -34,6 +34,23 @@ import org.apache.poi.util.IOUtils; | |||
*/ | |||
public class XWPFPictureData extends POIXMLDocumentPart { | |||
private static final int DEFAULT_MAX_IMAGE_SIZE = 100_000_000; | |||
private static int MAX_IMAGE_SIZE = DEFAULT_MAX_IMAGE_SIZE; | |||
/** | |||
* @param length the max image size allowed for XSSF pictures | |||
*/ | |||
public static void setMaxImageSize(int length) { | |||
MAX_IMAGE_SIZE = length; | |||
} | |||
/** | |||
* @return the max image size allowed for XSSF pictures | |||
*/ | |||
public static int getMaxImageSize() { | |||
return MAX_IMAGE_SIZE; | |||
} | |||
/** | |||
* Relationships for each known picture type | |||
*/ | |||
@@ -94,7 +111,7 @@ public class XWPFPictureData extends POIXMLDocumentPart { | |||
*/ | |||
public byte[] getData() { | |||
try (InputStream stream = getPackagePart().getInputStream()) { | |||
return IOUtils.toByteArray(stream); | |||
return IOUtils.toByteArray(stream, getMaxImageSize()); | |||
} catch (IOException e) { | |||
throw new POIXMLException(e); | |||
} | |||
@@ -146,15 +163,11 @@ public class XWPFPictureData extends POIXMLDocumentPart { | |||
public Long getChecksum() { | |||
if (this.checksum == null) { | |||
InputStream is = null; | |||
byte[] data; | |||
try { | |||
is = getPackagePart().getInputStream(); | |||
data = IOUtils.toByteArray(is); | |||
try (InputStream is = getPackagePart().getInputStream()) { | |||
data = IOUtils.toByteArray(is, getMaxImageSize()); | |||
} catch (IOException e) { | |||
throw new POIXMLException(e); | |||
} finally { | |||
IOUtils.closeQuietly(is); | |||
} | |||
this.checksum = IOUtils.calculateChecksum(data); | |||
} |