You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2026/02/02 17:16:14 UTC

(poi) branch trunk updated (8f149f51d0 -> 62ae400993)

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

centic pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


    from 8f149f51d0 Bump commons-codec:commons-codec from 1.20.0 to 1.21.0 (#1004)
     new ae3ed57baa Prevent a file-handle leak
     new 62ae400993 Do not call getColumn() twice

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/poi/xssf/usermodel/XSSFWorkbook.java | 21 +++++++++++++++------
 .../poi/xssf/usermodel/helpers/ColumnHelper.java    | 13 +++++++++----
 .../xssf/usermodel/helpers/TestColumnHelper.java    |  3 +--
 .../apache/poi/xwpf/usermodel/TestXWPFDocument.java | 12 ++++++++++++
 4 files changed, 37 insertions(+), 12 deletions(-)


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


(poi) 01/02: Prevent a file-handle leak

Posted by ce...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

centic pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git

commit ae3ed57baa41b3e4ec027213f9367b77aeeab2c3
Author: Dominik Stadler <do...@dynatrace.com>
AuthorDate: Fri Dec 5 11:55:12 2025 +0100

    Prevent a file-handle leak
    
    File-handles could leak when an exception occurs during
    class initialization when loading an broken workbook-file
---
 .../org/apache/poi/xssf/usermodel/XSSFWorkbook.java | 21 +++++++++++++++------
 .../apache/poi/xwpf/usermodel/TestXWPFDocument.java | 12 ++++++++++++
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index a063b4d8a9..1edd31d614 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -256,15 +256,24 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
      */
     public XSSFWorkbook(OPCPackage pkg) throws IOException {
         super(pkg);
-        this.xssfFactory = XSSFFactory.getInstance();
 
-        beforeDocumentRead();
+        try {
+            this.xssfFactory = XSSFFactory.getInstance();
 
-        // Build a tree of POIXMLDocumentParts, this workbook being the root
-        load(this.xssfFactory);
+            beforeDocumentRead();
 
-        // some broken Workbooks miss this...
-        setBookViewsIfMissing();
+            // Build a tree of POIXMLDocumentParts, this workbook being the root
+            load(this.xssfFactory);
+
+            // some broken Workbooks miss this...
+            setBookViewsIfMissing();
+        } catch (IOException | RuntimeException e) {
+            // close the package on exception to avoid file handle leaks
+            pkg.revert();
+
+            // rethrow exception
+            throw e;
+        }
     }
 
     /**
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 aefda3f01d..cc0349c283 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
@@ -44,6 +44,7 @@ import org.apache.poi.openxml4j.opc.PackageAccess;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.PackagePartName;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
 import org.apache.xmlbeans.XmlCursor;
@@ -512,6 +513,8 @@ public final class TestXWPFDocument {
             try (XWPFDocument doc = new XWPFDocument(
                     POIDataSamples.getDocumentInstance().openResourceAsStream("unicode-path.docx"))) {
                 // expect exception here
+
+                assertNotNull(doc);
             }
         });
         assertEquals("InvalidFormatException", ex.getCause().getClass().getSimpleName());
@@ -544,4 +547,13 @@ public final class TestXWPFDocument {
             }
         }
     }
+
+    @Test
+    void testFileHandleLeak() {
+        //noinspection resource
+        assertThrows(POIXMLException.class,
+                // Use XSSFWorkbook on purpose here to trigger missing closing of file-handle
+                () -> new XSSFWorkbook(
+                        POIDataSamples.getDocumentInstance().getFile("clusterfuzz-testcase-minimized-POIXWPFFuzzer-4791943399604224.docx")));
+    }
 }


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


(poi) 02/02: Do not call getColumn() twice

Posted by ce...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

centic pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git

commit 62ae400993f3d42edb08949f6d7fc63b030d879f
Author: Dominik Stadler <do...@dynatrace.com>
AuthorDate: Mon Feb 2 18:09:40 2026 +0100

    Do not call getColumn() twice
    
    It always iterates over the array of columns, so we
    should reuse the result here.
---
 .../org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java | 13 +++++++++----
 .../apache/poi/xssf/usermodel/helpers/TestColumnHelper.java |  3 +--
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
index a394b72d4a..6dcee13193 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
@@ -38,7 +38,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
  */
 public class ColumnHelper {
 
-    private CTWorksheet worksheet;
+    private final CTWorksheet worksheet;
 
     public ColumnHelper(CTWorksheet worksheet) {
         super();
@@ -303,10 +303,15 @@ public class ColumnHelper {
         col.setStyle(styleId);
     }
     
-    // Returns -1 if no column is found for the given index
+    /**
+     * Get the default style index for the given column index
+     *
+     * @return The style-index or -1 if no column is found for the given index
+     */
     public int getColDefaultStyle(long index) {
-        if (getColumn(index, false) != null) {
-            return (int) getColumn(index, false).getStyle();
+        final CTCol column = getColumn(index, false);
+        if (column != null) {
+            return (int) column.getStyle();
         }
         return -1;
     }
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
index 95ccbb3c8a..2c92887a0a 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
@@ -252,7 +252,7 @@ public final class TestColumnHelper {
     }
 
     /**
-     * Creates and adds a hidden column and then a best fit column with the given min/max pairs.
+     * Creates and adds a hidden column and then the best fit column with the given min/max pairs.
      * Suitable for testing handling of overlap.
      */
     private static CTCols createHiddenAndBestFitColsWithHelper(int hiddenMin, int hiddenMax, int bestFitMin, int bestFitMax) {
@@ -404,7 +404,6 @@ public final class TestColumnHelper {
         return count;
     }
 
-    @SuppressWarnings("deprecation")
     @Test
     void testColumnsCollapsed() throws IOException {
         try (XSSFWorkbook wb = new XSSFWorkbook()) {


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