This is an automated email from the ASF dual-hosted git repository.

pjfanning 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 4ea6fc68b5 Reject oversized XSSF table counts during integer 
conversion (#1067)
4ea6fc68b5 is described below

commit 4ea6fc68b5445655adcbdb424f4981dca46b3cb8
Author: metsw24-max <[email protected]>
AuthorDate: Wed May 13 13:35:52 2026 +0530

    Reject oversized XSSF table counts during integer conversion (#1067)
---
 .../main/java/org/apache/poi/xssf/usermodel/XSSFTable.java  |  9 +++++----
 .../java/org/apache/poi/xssf/usermodel/TestXSSFTable.java   | 13 +++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git 
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java 
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java
index 8b279fc720..480cc491c8 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java
@@ -789,9 +789,10 @@ public class XSSFTable extends POIXMLDocumentPart 
implements Table {
         if(tableColumns == null) {
             return 0;
         }
-        // Casting to int should be safe here - tables larger than the
+        // Reject oversized workbook-controlled table metadata instead of
+        // silently truncating during long-to-int conversion.
         // sheet (which holds the actual data of the table) can't exists.
-        return (int) tableColumns.getCount();
+        return Math.toIntExact(tableColumns.getCount());
     }
 
     /**
@@ -912,7 +913,7 @@ public class XSSFTable extends POIXMLDocumentPart 
implements Table {
      */
     @Override
     public int getTotalsRowCount() {
-        return (int) ctTable.getTotalsRowCount();
+        return Math.toIntExact(ctTable.getTotalsRowCount());
     }
 
     /**
@@ -922,7 +923,7 @@ public class XSSFTable extends POIXMLDocumentPart 
implements Table {
      */
     @Override
     public int getHeaderRowCount() {
-        return (int) ctTable.getHeaderRowCount();
+        return Math.toIntExact(ctTable.getHeaderRowCount());
     }
 
     /**
diff --git 
a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java 
b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
index 5fb20b6152..298f8084e0 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
@@ -162,6 +162,19 @@ public final class TestXSSFTable {
         }
     }
 
+    @Test
+    void oversizedTableCountsAreRejected() {
+        XSSFTable table = new XSSFTable();
+
+        table.getCTTable().setHeaderRowCount((long) Integer.MAX_VALUE + 1);
+        table.getCTTable().setTotalsRowCount((long) Integer.MAX_VALUE + 1);
+        table.getCTTable().addNewTableColumns().setCount((long) 
Integer.MAX_VALUE + 1);
+
+        assertThrows(ArithmeticException.class, table::getHeaderRowCount);
+        assertThrows(ArithmeticException.class, table::getTotalsRowCount);
+        assertThrows(ArithmeticException.class, table::getColumnCount);
+    }
+
     @Test
     void getStartColIndex() throws IOException {
         try (XSSFWorkbook wb = 
XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx")) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to