Avoid NPE when reading a broken xlsb file

Throw a more useful exception instead
This commit is contained in:
Dominik Stadler 2026-01-10 14:00:11 +01:00
parent ba04c61188
commit a5f5f4294e
4 changed files with 10 additions and 3 deletions

View File

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

View File

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

Binary file not shown.