aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2023-01-01 15:59:32 +0000
committerDominik Stadler <centic@apache.org>2023-01-01 15:59:32 +0000
commit5724a77cf2ea8a9fef1302a7bbd5da77a207c4ab (patch)
tree5951a7e1e04e78b53cf23956c8c452694dff83cc /poi-ooxml
parent012bf1a99afbd494f9c6b297a0fd3b5cffc959ab (diff)
downloadpoi-5724a77cf2ea8a9fef1302a7bbd5da77a207c4ab.tar.gz
poi-5724a77cf2ea8a9fef1302a7bbd5da77a207c4ab.zip
Avoid some NullPointerExceptions and ClassCastExceptions found when fuzzing Apache POI
This mostly only makes thrown exceptions a bit more consistent or may allow some broken documents to be still read. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1906322 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java3
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java3
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java5
5 files changed, 19 insertions, 0 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
index 8d90c78cce..6336836821 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
@@ -224,6 +224,9 @@ public class ReadOnlySharedStringsTable extends DefaultHandler implements Shared
@Override
public RichTextString getItemAt(int idx) {
+ if (strings == null || idx >= strings.size()) {
+ throw new IllegalStateException("Cannot get item at " + idx + " with strings: " + strings);
+ }
return new XSSFRichTextString(strings.get(idx));
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
index 8a2fd78c3c..c4062e1cd6 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
@@ -300,6 +300,9 @@ public class XSSFReader {
* @throws IOException if there is an I/O issue reading the data
*/
protected SheetIterator(PackagePart wb) throws IOException, InvalidFormatException {
+ if (wb == null) {
+ throw new InvalidFormatException("Cannot create sheet-iterator with missing package part for workbook");
+ }
/*
* The order of sheets is defined by the order of CTSheet elements in workbook.xml
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index 7dec278354..3cc13f1d9c 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -3751,6 +3751,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx
}
protected void write(OutputStream out) throws IOException {
+ if (worksheet == null) {
+ throw new POIXMLException("Cannot write invalid sheet, internal data is missing");
+ }
+
boolean setToNull = false;
if(worksheet.sizeOfColsArray() == 1) {
CTCols col = worksheet.getColsArray(0);
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java
index 203ac46288..1aff90af29 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java
@@ -59,6 +59,10 @@ public class XWPFComments extends POIXMLDocumentPart {
*/
public XWPFComments(POIXMLDocumentPart parent, PackagePart part) {
super(parent, part);
+
+ if (!(getParent() instanceof XWPFDocument)) {
+ throw new IllegalStateException("Parent is not a XWPFDocuemnt: " + getParent());
+ }
this.document = (XWPFDocument) getParent();
if (this.document == null) {
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java
index da22abe359..03deae1cd1 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java
@@ -32,6 +32,11 @@ public class XWPFPicture {
public XWPFPicture(CTPicture ctPic, XWPFRun run) {
this.run = run;
this.ctPic = ctPic;
+
+ if (ctPic == null || ctPic.getNvPicPr() == null || ctPic.getNvPicPr().getCNvPr() == null) {
+ throw new IllegalArgumentException("Found missing data while reading picture data from " + ctPic);
+ }
+
description = ctPic.getNvPicPr().getCNvPr().getDescr();
}