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 a5f5f4294efd6929eeafa4528bffe91daa21ebad
Author: Dominik Stadler <[email protected]>
AuthorDate: Sat Jan 10 14:00:11 2026 +0100

    Avoid NPE when reading a broken xlsb file
    
    Throw a more useful exception instead
---
 .../apache/poi/xssf/binary/XSSFBSheetHandler.java   |   8 ++++++--
 .../apache/poi/hssf/dev/BaseTestIteratingXLS.java   |   5 ++++-
 ..._files_rde_documents_vodootvedenie_2020.xlsb.xls | Bin 0 -> 1048576 bytes
 test-data/spreadsheet/stress.xls                    | Bin 75264 -> 75776 bytes
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git 
a/poi-ooxml/src/main/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java 
b/poi-ooxml/src/main/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java
index 8f8a7d2a93..8e89cadc16 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java
@@ -88,7 +88,7 @@ public class XSSFBSheetHandler extends XSSFBParser {
     /**
      * Creates a handler that converts numeric and date cells to formatted 
strings via {@link
      * DataFormatter}.
-     * 
+     *
      * <p>Select this overload when the consumer expects formatted string 
values rather than raw
      * cell representations.
      *
@@ -224,6 +224,10 @@ public class XSSFBSheetHandler extends XSSFBParser {
     }
 
     private ExcelNumberFormat getExcelNumberFormat() {
+        if (styles == null) {
+            throw new IllegalStateException("Cannot read information because 
styles-table is not available");
+        }
+
         int styleIdx = cellBuffer.getStyleIdx();
         String formatString = styles.getNumberFormatString(styleIdx);
         short styleIndex = styles.getNumberFormatIndex(styleIdx);
@@ -399,7 +403,7 @@ public class XSSFBSheetHandler extends XSSFBParser {
 
         rkBuffer[4] = b0;
         System.arraycopy(data, offset + 1, rkBuffer, 5, 3);
-        double d = 0.0;
+        double d;
         if (floatingPoint) {
             d = LittleEndian.getDouble(rkBuffer);
         } else {
diff --git 
a/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java 
b/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java
index 5ac8864f17..bdf55860f4 100644
--- a/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java
+++ b/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java
@@ -28,6 +28,7 @@ import java.util.stream.Stream;
 
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hssf.OldExcelFormatException;
+import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
 import org.apache.poi.util.RecordFormatException;
 import org.apache.tools.ant.DirectoryScanner;
 import org.junit.jupiter.api.TestInstance;
@@ -91,12 +92,14 @@ public abstract class BaseTestIteratingXLS {
         
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-4819588401201152.xls",
 RuntimeException.class);
         
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6537773940867072.xls",
 RuntimeException.class);
         
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-4651309315719168.xls",
 RuntimeException.class);
+        
excludes.put("rde.imf.ru_sites_default_files_rde_documents_vodootvedenie_2020.xlsb.xls",
 OfficeXmlFileException.class);
+
         return excludes;
     }
 
     @ParameterizedTest
     @MethodSource("files")
-    void testMain(File file, Class<? extends Throwable> t) throws Exception {
+    void testMain(File file, Class<? extends Throwable> t) {
         // avoid running files leftover from previous failed runs
         // or created by tests running in parallel
         // otherwise this would cause sporadic failures with
diff --git 
a/test-data/spreadsheet/rde.imf.ru_sites_default_files_rde_documents_vodootvedenie_2020.xlsb.xls
 
b/test-data/spreadsheet/rde.imf.ru_sites_default_files_rde_documents_vodootvedenie_2020.xlsb.xls
new file mode 100644
index 0000000000..eed8331ba3
Binary files /dev/null and 
b/test-data/spreadsheet/rde.imf.ru_sites_default_files_rde_documents_vodootvedenie_2020.xlsb.xls
 differ
diff --git a/test-data/spreadsheet/stress.xls b/test-data/spreadsheet/stress.xls
index 4b0be32353..0ff3b117ca 100644
Binary files a/test-data/spreadsheet/stress.xls and 
b/test-data/spreadsheet/stress.xls differ


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

Reply via email to