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 e5b2fbb89b add depth check (#858)
e5b2fbb89b is described below

commit e5b2fbb89b7d704d69f64825dd03d819545f28f7
Author: PJ Fanning <pjfann...@users.noreply.github.com>
AuthorDate: Wed Jul 23 20:27:40 2025 +0100

    add depth check (#858)
    
    * add depth check
    
    * Update XWPFTableCell.java
    
    * Update XWPFTableCell.java
    
    * Update XWPFTableCell.java
    
    * Update XWPFTableCell.java
---
 .../org/apache/poi/xwpf/usermodel/XWPFTableCell.java  | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git 
a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java 
b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
index f91d9a1d81..d8d3304e99 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
@@ -524,7 +524,24 @@ public class XWPFTableCell implements IBody, ICell {
 
     @Override
     public XWPFDocument getXWPFDocument() {
-        return part.getXWPFDocument();
+        if (part instanceof XWPFTableCell) {
+            return getCellDocument((XWPFTableCell) part, 0);
+        } else {
+            return part.getXWPFDocument();
+        }
+    }
+
+    private static final int MAX_RECURSION_DEPTH = 1000;
+
+    private static XWPFDocument getCellDocument(XWPFTableCell cell, final int 
depth) {
+        if (depth > MAX_RECURSION_DEPTH) {
+            throw new IllegalStateException("Recursion depth exceeded while 
trying to get XWPFDocument from XWPFTableCell");
+        }
+        if (cell.part instanceof XWPFTableCell) {
+            return getCellDocument((XWPFTableCell) cell.part, depth + 1);
+        } else {
+            return cell.part.getXWPFDocument();
+        }
     }
 
     // Create a map from this XWPF-level enum to the STVerticalJc.Enum values


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to