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 3156f8b5c2 Stop MainExtractorFactory swallowing fatal errors (#1254)
3156f8b5c2 is described below

commit 3156f8b5c208ffc7ddc76f0bb7f53b18016476e6
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Sep 7 13:25:00 2026 +0100

    Stop MainExtractorFactory swallowing fatal errors (#1254)
    
    Both create(File, String) and create(InputStream, String) guarded their
    cleanup with an inverted fatal check:
    
        } catch (Throwable t) {
            if (!ExceptionUtil.isFatal(t)) {
                fs.close();
                throw t;
            }
        }
    
    For a fatal throwable - VirtualMachineError, ThreadDeath - the catch body
    does nothing at all. Execution falls through to the "extractor == null"
    branch and the method returns null, so an OutOfMemoryError raised while
    building the extractor is reported to the caller as "no extractor for
    this file".
    
    The rest of the codebase uses the opposite form, rethrowing fatal
    throwables rather than suppressing them - see XMLHelper, CleanerUtil and
    HSSFParser.
    
    There is nothing here that needs to treat fatal throwables differently:
    the only work in the catch block is closing a filesystem this method
    opened and owns. Drop the isFatal check so every throwable propagates,
    and switch to IOUtils.closeQuietly so a failure while closing cannot mask
    the original throwable. ExtractorFactory.createExtractor uses the same
    closeQuietly-then-rethrow shape.
    
    The filesystem is still closed on every failure path, so this does not
    reintroduce a leak.
    
    Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
---
 .../apache/poi/extractor/MainExtractorFactory.java | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git 
a/poi/src/main/java/org/apache/poi/extractor/MainExtractorFactory.java 
b/poi/src/main/java/org/apache/poi/extractor/MainExtractorFactory.java
index 8a39bc360a..fb53174fcf 100644
--- a/poi/src/main/java/org/apache/poi/extractor/MainExtractorFactory.java
+++ b/poi/src/main/java/org/apache/poi/extractor/MainExtractorFactory.java
@@ -31,7 +31,7 @@ import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.FileMagic;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.ExceptionUtil;
+import org.apache.poi.util.IOUtils;
 
 /**
  * ExtractorFactory for HSSF and Old Excel format
@@ -46,14 +46,14 @@ public class MainExtractorFactory implements 
ExtractorProvider {
     @Override
     public POITextExtractor create(File file, String password) throws 
IOException {
         POIFSFileSystem fs = new POIFSFileSystem(file, true);
-        POITextExtractor extractor = null;
+        POITextExtractor extractor;
         try {
             extractor = create(fs.getRoot(), password);
         } catch (Throwable t) {
-            if (!ExceptionUtil.isFatal(t)) {
-                fs.close();
-                throw t;
-            }
+            // this method owns fs and construction did not complete, so close 
it and let
+            // every throwable through - including fatal ones such as 
VirtualMachineError
+            IOUtils.closeQuietly(fs);
+            throw t;
         }
         if (extractor == null) {
             fs.close();
@@ -64,14 +64,14 @@ public class MainExtractorFactory implements 
ExtractorProvider {
     @Override
     public POITextExtractor create(InputStream inputStream, String password) 
throws IOException {
         POIFSFileSystem fs = new POIFSFileSystem(inputStream);
-        POITextExtractor extractor = null;
+        POITextExtractor extractor;
         try {
             extractor = create(fs.getRoot(), password);
         } catch (Throwable t) {
-            if (!ExceptionUtil.isFatal(t)) {
-                fs.close();
-                throw t;
-            }
+            // this method owns fs and construction did not complete, so close 
it and let
+            // every throwable through - including fatal ones such as 
VirtualMachineError
+            IOUtils.closeQuietly(fs);
+            throw t;
         }
         if (extractor == null) {
             fs.close();


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

Reply via email to