Browse Source

Bug 66425: Avoid NullPointerExceptions found via poi-fuzz

We try to avoid throwing NullPointerException, but it was possible
to trigger one here

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912281 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_4
Dominik Stadler 8 months ago
parent
commit
cc4ccbae1d

+ 3
- 2
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java View File

XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement( xmlOptions.setSaveSyntheticDocumentElement(
new QName(CTChartsheet.type.getName().getNamespaceURI(), "chartsheet")); new QName(CTChartsheet.type.getName().getNamespaceURI(), "chartsheet"));
chartsheet.save(out, xmlOptions);

if (chartsheet != null) {
chartsheet.save(out, xmlOptions);
}
} }


private static byte[] blankWorksheet(){ private static byte[] blankWorksheet(){

+ 8
- 0
poi-ooxml/src/test/java/org/apache/poi/ss/tests/TestWorkbookFactory.java View File

return false; return false;
} }
} }

@Test
void testEncryptionNullPointerException() throws IOException {
assertThrows(IllegalArgumentException.class,
() -> WorkbookFactory.create(POIDataSamples.getSpreadSheetInstance().
openResourceAsStream(
"crash-9bf3cd4bd6f50a8a9339d363c2c7af14b536865c.xlsx")));
}
} }

+ 6
- 0
poi/src/main/java/org/apache/poi/poifs/crypt/CryptoFunctions.java View File

if (cipherAlgorithm == CipherAlgorithm.rc4) { if (cipherAlgorithm == CipherAlgorithm.rc4) {
cipher = Cipher.getInstance(cipherAlgorithm.jceId); cipher = Cipher.getInstance(cipherAlgorithm.jceId);
} else if (cipherAlgorithm.needsBouncyCastle) { } else if (cipherAlgorithm.needsBouncyCastle) {
if (chain == null) {
throw new IllegalArgumentException("Did not have a chain for cipher " + cipherAlgorithm);
}
registerBouncyCastle(); registerBouncyCastle();
cipher = Cipher.getInstance(cipherAlgorithm.jceId + "/" + chain.jceId + "/" + padding, "BC"); cipher = Cipher.getInstance(cipherAlgorithm.jceId + "/" + chain.jceId + "/" + padding, "BC");
} else { } else {
if (chain == null) {
throw new IllegalArgumentException("Did not have a chain for cipher " + cipherAlgorithm);
}
cipher = Cipher.getInstance(cipherAlgorithm.jceId + "/" + chain.jceId + "/" + padding); cipher = Cipher.getInstance(cipherAlgorithm.jceId + "/" + chain.jceId + "/" + padding);
} }



BIN
test-data/spreadsheet/crash-274d6342e4842d61be0fb48eaadad6208ae767ae.xlsx View File


BIN
test-data/spreadsheet/crash-9bf3cd4bd6f50a8a9339d363c2c7af14b536865c.xlsx View File


BIN
test-data/spreadsheet/stress.xls View File


Loading…
Cancel
Save