This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 528591ba11 Allow to load a word document with chartex chart (#982)
528591ba11 is described below
commit 528591ba11849245b8ce12cefffe589d25d7f10a
Author: emmanueldufour <[email protected]>
AuthorDate: Sat Dec 20 02:10:25 2025 +0700
Allow to load a word document with chartex chart (#982)
* Allow to load a word document with chartex chart
ChartEx (new charts introduced in Office 2016) will raise exceptions in
underlying XML parsing, we catch them here in order to still be able to load
the document
* spacing
some extra spaces were unbearable and could have prevented the pull request
* add test
* Update POIXMLDocumentPart.java
* Update POIXMLDocumentPart.java
* Update POIXMLDocumentPart.java
* reduce risk of swallowing zip bomb exceptions
* Update POIXMLDocumentPart.java
---------
Co-authored-by: PJ Fanning <[email protected]>
---
.../org/apache/poi/ooxml/POIXMLDocumentPart.java | 19 +++++++++++++++++--
.../apache/poi/xwpf/usermodel/TestXWPFDocument.java | 9 +++++++++
src/resources/ooxml-lite-report.xsb | 1 +
test-data/document/chartex.docx | Bin 0 -> 133304 bytes
4 files changed, 27 insertions(+), 2 deletions(-)
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
index 64ed50b4bd..9a619a410f 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
@@ -45,6 +45,7 @@ import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
+import org.apache.xmlbeans.XmlException;
/**
* Represents an entry of a OOXML package.
@@ -668,8 +669,22 @@ public class POIXMLDocumentPart {
POIXMLDocumentPart childPart = context.get(p);
if (childPart == null) {
- childPart = factory.createDocumentPart(this, p);
- //here we are checking if part if embedded and excel
then set it to chart class
+ try {
+ childPart = factory.createDocumentPart(this, p);
+ } catch (POIXMLException e) {
+ if (e.getCause() instanceof XmlException
+ &&
XSSFRelation.CHART.getRelation().equals(rel.getRelationshipType())) {
+ // https://github.com/apache/poi/pull/982
+ // only allow this skipping event for charts
+ // we need to be careful about not catching
every exception here because
+ // issues like zip bomb exceptions need to
thrown and not ignored
+ LOG.atWarn().log("Skipped unsupported part:
{}", e.getMessage());
+ continue;
+ } else {
+ throw e;
+ }
+ }
+ //here we are checking if part is embedded and excel
then set it to chart class
//so that at the time to writing we can also write
updated embedded part
if (this instanceof XDDFChart && childPart instanceof
XSSFWorkbook) {
((XDDFChart) this).setWorkbook((XSSFWorkbook)
childPart);
diff --git
a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
index 36c30a7428..aefda3f01d 100644
---
a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
+++
b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
@@ -517,6 +517,15 @@ public final class TestXWPFDocument {
assertEquals("InvalidFormatException",
ex.getCause().getClass().getSimpleName());
}
+ @Test
+ void testChartExIgnored() throws IOException {
+ // see https://github.com/apache/poi/pull/982
+ try (XWPFDocument doc = new XWPFDocument(
+
POIDataSamples.getDocumentInstance().openResourceAsStream("chartex.docx"))) {
+ assertNotNull(doc);
+ }
+ }
+
@Test
@Disabled("XWPF should be able to write to a new Stream when opened
Read-Only")
void testWriteFromReadOnlyOPC() throws Exception {
diff --git a/src/resources/ooxml-lite-report.xsb
b/src/resources/ooxml-lite-report.xsb
index e058876cc7..7f3d358103 100644
--- a/src/resources/ooxml-lite-report.xsb
+++ b/src/resources/ooxml-lite-report.xsb
@@ -1185,3 +1185,4 @@ ctpivotareareferencee5a5type
ctindex5371type
stholesizepercenta3d2type
stholesizeubyte577atype
+chartspace67aadoctype
diff --git a/test-data/document/chartex.docx b/test-data/document/chartex.docx
new file mode 100644
index 0000000000..79b1cb639a
Binary files /dev/null and b/test-data/document/chartex.docx differ
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]