mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40: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
@ -224,6 +224,10 @@ public class XSSFBSheetHandler extends XSSFBParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ExcelNumberFormat getExcelNumberFormat() {
|
private ExcelNumberFormat getExcelNumberFormat() {
|
||||||
|
if (styles == null) {
|
||||||
|
throw new IllegalStateException("Cannot read information because styles-table is not available");
|
||||||
|
}
|
||||||
|
|
||||||
int styleIdx = cellBuffer.getStyleIdx();
|
int styleIdx = cellBuffer.getStyleIdx();
|
||||||
String formatString = styles.getNumberFormatString(styleIdx);
|
String formatString = styles.getNumberFormatString(styleIdx);
|
||||||
short styleIndex = styles.getNumberFormatIndex(styleIdx);
|
short styleIndex = styles.getNumberFormatIndex(styleIdx);
|
||||||
@ -399,7 +403,7 @@ public class XSSFBSheetHandler extends XSSFBParser {
|
|||||||
|
|
||||||
rkBuffer[4] = b0;
|
rkBuffer[4] = b0;
|
||||||
System.arraycopy(data, offset + 1, rkBuffer, 5, 3);
|
System.arraycopy(data, offset + 1, rkBuffer, 5, 3);
|
||||||
double d = 0.0;
|
double d;
|
||||||
if (floatingPoint) {
|
if (floatingPoint) {
|
||||||
d = LittleEndian.getDouble(rkBuffer);
|
d = LittleEndian.getDouble(rkBuffer);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hssf.OldExcelFormatException;
|
import org.apache.poi.hssf.OldExcelFormatException;
|
||||||
|
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
|
||||||
import org.apache.poi.util.RecordFormatException;
|
import org.apache.poi.util.RecordFormatException;
|
||||||
import org.apache.tools.ant.DirectoryScanner;
|
import org.apache.tools.ant.DirectoryScanner;
|
||||||
import org.junit.jupiter.api.TestInstance;
|
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-4819588401201152.xls", RuntimeException.class);
|
||||||
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6537773940867072.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("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;
|
return excludes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("files")
|
@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
|
// avoid running files leftover from previous failed runs
|
||||||
// or created by tests running in parallel
|
// or created by tests running in parallel
|
||||||
// otherwise this would cause sporadic failures with
|
// otherwise this would cause sporadic failures with
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user