Avoid a possible NullPointerException Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67922 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917269 13f79535-47bb-0310-9956-ffa450edef68pull/625/head
final long id = p.getID(); | final long id = p.getID(); | ||||
if (id == PropertyIDMap.PID_CODEPAGE) { | if (id == PropertyIDMap.PID_CODEPAGE) { | ||||
cps.setCodepage((Integer)p.getValue()); | cps.setCodepage((Integer)p.getValue()); | ||||
} else if (id > PropertyIDMap.PID_CODEPAGE) { | |||||
} else if (id > PropertyIDMap.PID_CODEPAGE && dictionary != null) { | |||||
propertyCount++; | propertyCount++; | ||||
final CustomProperty cp = new CustomProperty(p, dictionary.get(id)); | final CustomProperty cp = new CustomProperty(p, dictionary.get(id)); | ||||
cps.put(cp.getName(), cp); | cps.put(cp.getName(), cp); |
package org.apache.poi.hpsf.extractor; | package org.apache.poi.hpsf.extractor; | ||||
import static org.apache.poi.POITestCase.assertContains; | |||||
import static org.junit.jupiter.api.Assertions.assertEquals; | |||||
import static org.junit.jupiter.api.Assertions.assertNotNull; | |||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
import org.apache.commons.io.FileUtils; | |||||
import org.apache.poi.POIDataSamples; | import org.apache.poi.POIDataSamples; | ||||
import org.apache.poi.extractor.ExtractorFactory; | |||||
import org.apache.poi.extractor.POIOLE2TextExtractor; | |||||
import org.apache.poi.extractor.POITextExtractor; | |||||
import org.apache.poi.hpsf.Thumbnail; | import org.apache.poi.hpsf.Thumbnail; | ||||
import org.apache.poi.hssf.HSSFTestDataSamples; | import org.apache.poi.hssf.HSSFTestDataSamples; | ||||
import org.apache.poi.hssf.extractor.ExcelExtractor; | import org.apache.poi.hssf.extractor.ExcelExtractor; | ||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | import org.apache.poi.poifs.filesystem.POIFSFileSystem; | ||||
import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||
import java.io.ByteArrayInputStream; | |||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
import static org.apache.poi.POITestCase.assertContains; | |||||
import static org.junit.jupiter.api.Assertions.assertEquals; | |||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | |||||
import static org.junit.jupiter.api.Assertions.assertNotNull; | |||||
final class TestHPSFPropertiesExtractor { | final class TestHPSFPropertiesExtractor { | ||||
private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance(); | private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance(); | ||||
assertContains(ext.getText(), "PID_CODEPAGE = 1252"); | assertContains(ext.getText(), "PID_CODEPAGE = 1252"); | ||||
} | } | ||||
} | } | ||||
@Test | |||||
void testNPE() throws IOException { | |||||
final byte[] bytes = FileUtils.readFileToByteArray( | |||||
POIDataSamples.getSpreadSheetInstance().getFile( | |||||
"clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls")); | |||||
try (POITextExtractor extractor = ExtractorFactory.createExtractor(new ByteArrayInputStream(bytes))) { | |||||
assertInstanceOf(POIOLE2TextExtractor.class, extractor); | |||||
POIOLE2TextExtractor ole2Extractor = (POIOLE2TextExtractor) extractor; | |||||
POITextExtractor[] embedded = ExtractorFactory.getEmbeddedDocsTextExtractors(ole2Extractor); | |||||
assertEquals(1, embedded.length); | |||||
for (POITextExtractor poiTextExtractor : embedded) { | |||||
POITextExtractor metaData = poiTextExtractor.getMetadataTextExtractor(); | |||||
metaData.getText(); | |||||
} | |||||
} | |||||
} | |||||
} | } |
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", IndexOutOfBoundsException.class); | excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", IndexOutOfBoundsException.class); | ||||
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6137883240824832.xls", IndexOutOfBoundsException.class); | excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6137883240824832.xls", IndexOutOfBoundsException.class); | ||||
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls", IndexOutOfBoundsException.class); | excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls", IndexOutOfBoundsException.class); | ||||
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls", RecordFormatException.class); | |||||
return excludes; | return excludes; | ||||
} | } |
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", RecordFormatException.class); | excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", RecordFormatException.class); | ||||
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6137883240824832.xls", RecordFormatException.class); | excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6137883240824832.xls", RecordFormatException.class); | ||||
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls", RecordFormatException.class); | excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls", RecordFormatException.class); | ||||
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5816431116615680.xls", RecordFormatException.class); | |||||
return excludes; | return excludes; | ||||
} | } |