Author: fanningpj
Date: Wed Mar 26 20:52:10 2025
New Revision: 1924643
URL: http://svn.apache.org/viewvc?rev=1924643&view=rev
Log:
[bug-69628] add test case
Added:
poi/trunk/test-data/document/bug69628.docx (with props)
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java?rev=1924643&r1=1924642&r2=1924643&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
Wed Mar 26 20:52:10 2025
@@ -44,7 +44,11 @@ public final class ZipArchiveFakeEntry e
private static int MAX_ENTRY_SIZE = DEFAULT_MAX_ENTRY_SIZE;
public static void setMaxEntrySize(int maxEntrySize) {
- MAX_ENTRY_SIZE = maxEntrySize;
+ if(maxEntrySize < 0) {
+ MAX_ENTRY_SIZE = DEFAULT_MAX_ENTRY_SIZE;
+ } else {
+ MAX_ENTRY_SIZE = maxEntrySize;
+ }
}
public static int getMaxEntrySize() {
@@ -61,7 +65,7 @@ public final class ZipArchiveFakeEntry e
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()) {
Modified:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java?rev=1924643&r1=1924642&r2=1924643&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
(original)
+++
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
Wed Mar 26 20:52:10 2025
@@ -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;
@@ -149,22 +152,22 @@ class TestXWPFBugs {
}
}
- /**
- * Removing a run needs to take into account position of run if paragraph
contains hyperlink runs
- */
- @Test
- void test58618() throws IOException {
- try (XWPFDocument doc =
XWPFTestDataSamples.openSampleDocument("58618.docx")) {
- XWPFParagraph para = (XWPFParagraph) doc.getBodyElements().get(0);
- assertNotNull(para);
- assertEquals("Some text some hyper links link link and some
text.....", para.getText());
- XWPFRun run = para.insertNewRun(para.getRuns().size());
- run.setText("New Text");
- assertEquals("Some text some hyper links link link and some
text.....New Text", para.getText());
- para.removeRun(para.getRuns().size() - 2);
- assertEquals("Some text some hyper links link linkNew Text",
para.getText());
- }
- }
+ /**
+ * Removing a run needs to take into account position of run if paragraph
contains hyperlink runs
+ */
+ @Test
+ void test58618() throws IOException {
+ try (XWPFDocument doc =
XWPFTestDataSamples.openSampleDocument("58618.docx")) {
+ XWPFParagraph para = (XWPFParagraph) doc.getBodyElements().get(0);
+ assertNotNull(para);
+ assertEquals("Some text some hyper links link link and some
text.....", para.getText());
+ XWPFRun run = para.insertNewRun(para.getRuns().size());
+ run.setText("New Text");
+ assertEquals("Some text some hyper links link link and some
text.....New Text", para.getText());
+ para.removeRun(para.getRuns().size() - 2);
+ assertEquals("Some text some hyper links link linkNew Text",
para.getText());
+ }
+ }
@Test
void test59378() throws IOException {
@@ -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);
+ }
+ }
}
Added: poi/trunk/test-data/document/bug69628.docx
URL:
http://svn.apache.org/viewvc/poi/trunk/test-data/document/bug69628.docx?rev=1924643&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/document/bug69628.docx
------------------------------------------------------------------------------
--- svn:mime-type (added)
+++ svn:mime-type Wed Mar 26 20:52:10 2025
@@ -0,0 +1 @@
+application/vnd.openxmlformats-officedocument.wordprocessingml.document
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]