[bug-69628] add test case

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1924643 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2025-03-26 20:52:10 +00:00
parent f90274e518
commit 9a6bd3902d
3 changed files with 49 additions and 19 deletions

View File

@ -44,8 +44,12 @@ public final class ZipArchiveFakeEntry extends ZipArchiveEntry implements Closea
private static int MAX_ENTRY_SIZE = DEFAULT_MAX_ENTRY_SIZE;
public static void setMaxEntrySize(int maxEntrySize) {
if(maxEntrySize < 0) {
MAX_ENTRY_SIZE = DEFAULT_MAX_ENTRY_SIZE;
} else {
MAX_ENTRY_SIZE = maxEntrySize;
}
}
public static int getMaxEntrySize() {
return MAX_ENTRY_SIZE;
@ -61,7 +65,7 @@ public final class ZipArchiveFakeEntry extends ZipArchiveEntry implements Closea
final long entrySize = entry.getSize();
final int threshold = ZipInputStreamZipEntrySource.getThresholdBytesForTempFiles();
if (threshold >= 0 && entrySize >= threshold) {
if (threshold >= 0 && (entrySize >= threshold || entrySize == -1)) {
if (ZipInputStreamZipEntrySource.shouldEncryptTempFiles()) {
encryptedTempData = new EncryptedTempData();
try (OutputStream os = encryptedTempData.getOutputStream()) {

View File

@ -28,6 +28,9 @@ import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import org.apache.poi.openxml4j.util.ZipArchiveFakeEntry;
import org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange;
@ -329,7 +332,7 @@ class TestXWPFBugs {
}
}
private static void addNumberingWithAbstractId(XWPFNumbering documentNumbering, int id){
private static void addNumberingWithAbstractId(XWPFNumbering documentNumbering, int id) {
// create a numbering scheme
CTAbstractNum cTAbstractNum = CTAbstractNum.Factory.newInstance();
// give the scheme an ID
@ -340,4 +343,27 @@ class TestXWPFBugs {
documentNumbering.addNum(abstractNumID);
}
@Test
void testBug69628() throws IOException {
final int expectedParagraphs = 24;
// bug69628.docx has -1 entry sizes in the zip data
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("bug69628.docx")) {
assertEquals(expectedParagraphs, doc.getParagraphs().size());
}
// test again with smaller byte array max
ZipArchiveFakeEntry.setMaxEntrySize(30 * 1024 * 1024);
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("bug69628.docx")) {
assertEquals(expectedParagraphs, doc.getParagraphs().size());
} finally {
ZipArchiveFakeEntry.setMaxEntrySize(-1);
}
// test again but temp files enabled
ZipInputStreamZipEntrySource.setThresholdBytesForTempFiles(1000);
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("bug69628.docx")) {
assertEquals(expectedParagraphs, doc.getParagraphs().size());
} finally {
ZipInputStreamZipEntrySource.setThresholdBytesForTempFiles(-1);
}
}
}

Binary file not shown.