Skip to content

Commit

Permalink
Bug 66425: Avoid NullPointerExceptions found via poi-fuzz
Browse files Browse the repository at this point in the history
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
  • Loading branch information
centic9 committed Sep 13, 2023
1 parent 4b70989 commit cc4ccba
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ protected void write(OutputStream out) throws IOException {
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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,12 @@ private boolean openHSSFFile() {
return false;
}
}

@Test
void testEncryptionNullPointerException() throws IOException {
assertThrows(IllegalArgumentException.class,
() -> WorkbookFactory.create(POIDataSamples.getSpreadSheetInstance().
openResourceAsStream(
"crash-9bf3cd4bd6f50a8a9339d363c2c7af14b536865c.xlsx")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,15 @@ public static Cipher getCipher(Key key, CipherAlgorithm cipherAlgorithm, Chainin
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);
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified test-data/spreadsheet/stress.xls
Binary file not shown.

0 comments on commit cc4ccba

Please sign in to comment.