Add reproducer for possible OOM when reading pictures in XWPF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899074 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2022-03-20 06:52:55 +00:00
parent d648c6d652
commit 306dc69105
1 changed files with 14 additions and 1 deletions

View File

@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -63,6 +62,20 @@ class TestXWPFPictureData {
}
}
@Test
void testReadMaxSize() throws InvalidFormatException, IOException {
int prev = XWPFPictureData.getMaxImageSize();
try {
// check for a regression in 5.2.1:
// even if we set the maximum to a very high value it should not
// simply allocate that much here
XWPFPictureData.setMaxImageSize(Integer.MAX_VALUE-1);
testRead();
} finally {
XWPFPictureData.setMaxImageSize(prev);
}
}
@Test
void testPictureInHeader() throws IOException {
try (XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx")) {