mirror of
https://github.com/apache/poi.git
synced 2026-02-27 12:30:08 +08:00
Avoid NPE when reading a broken xlsb file
Throw a more useful exception instead
This commit is contained in:
parent
ba04c61188
commit
a5f5f4294e
@ -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 {
|
||||
|
||||
@ -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.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user