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
This commit is contained in:
Dominik Stadler 2023-09-13 10:59:54 +00:00
parent 4b70989156
commit cc4ccbae1d
6 changed files with 17 additions and 2 deletions

View File

@ -90,8 +90,9 @@ public class XSSFChartSheet extends XSSFSheet {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(
new QName(CTChartsheet.type.getName().getNamespaceURI(), "chartsheet"));
chartsheet.save(out, xmlOptions);
if (chartsheet != null) {
chartsheet.save(out, xmlOptions);
}
}
private static byte[] blankWorksheet(){

View File

@ -351,4 +351,12 @@ public final class TestWorkbookFactory {
return false;
}
}
@Test
void testEncryptionNullPointerException() throws IOException {
assertThrows(IllegalArgumentException.class,
() -> WorkbookFactory.create(POIDataSamples.getSpreadSheetInstance().
openResourceAsStream(
"crash-9bf3cd4bd6f50a8a9339d363c2c7af14b536865c.xlsx")));
}
}

View File

@ -252,9 +252,15 @@ public final class CryptoFunctions {
if (cipherAlgorithm == CipherAlgorithm.rc4) {
cipher = Cipher.getInstance(cipherAlgorithm.jceId);
} else if (cipherAlgorithm.needsBouncyCastle) {
if (chain == null) {
throw new IllegalArgumentException("Did not have a chain for cipher " + cipherAlgorithm);
}
registerBouncyCastle();
cipher = Cipher.getInstance(cipherAlgorithm.jceId + "/" + chain.jceId + "/" + padding, "BC");
} else {
if (chain == null) {
throw new IllegalArgumentException("Did not have a chain for cipher " + cipherAlgorithm);
}
cipher = Cipher.getInstance(cipherAlgorithm.jceId + "/" + chain.jceId + "/" + padding);
}

Binary file not shown.