add depth check (#858)

* add depth check

* Update XWPFTableCell.java

* Update XWPFTableCell.java

* Update XWPFTableCell.java

* Update XWPFTableCell.java
This commit is contained in:
PJ Fanning 2025-07-23 20:27:40 +01:00 committed by GitHub
parent 8fc2f7db41
commit e5b2fbb89b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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