aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2023-08-24 08:48:45 +0000
committerDominik Stadler <centic@apache.org>2023-08-24 08:48:45 +0000
commitcdb2ba13989badf60d88c75daf69c94ae6ac2e13 (patch)
treeeac04a08a91f883d7d0927e964332abad80460be
parente4ba9822cc4fe70de83aad413b2b21eef551661f (diff)
downloadpoi-cdb2ba13989badf60d88c75daf69c94ae6ac2e13.tar.gz
poi-cdb2ba13989badf60d88c75daf69c94ae6ac2e13.zip
Bug 66425: Avoid a NullPointerException found via oss-fuzz
We try to avoid throwing NullPointerException, but it was possible to trigger one here with a specially crafted input-file Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61441 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911890 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java19
-rw-r--r--test-data/slideshow/clusterfuzz-testcase-minimized-POIFuzzer-5205835528404992.pptxbin0 -> 36689 bytes
-rw-r--r--test-data/spreadsheet/stress.xlsbin66048 -> 67072 bytes
3 files changed, 8 insertions, 11 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java
index 350e63e22d..44feeefeb4 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java
@@ -45,14 +45,9 @@ public final class PackageRelationshipCollection implements Iterable<PackageRela
private final TreeMap<String, PackageRelationship> relationshipsByID = new TreeMap<>();
/**
- * Package relationships ordered by type.
- */
- private final TreeMap<String, PackageRelationship> relationshipsByType = new TreeMap<>();
-
- /**
* A lookup of internal relationships to avoid
*/
- private HashMap<String, PackageRelationship> internalRelationshipsByTargetName = new HashMap<>();
+ private final HashMap<String, PackageRelationship> internalRelationshipsByTargetName = new HashMap<>();
/**
@@ -195,7 +190,6 @@ public final class PackageRelationshipCollection implements Iterable<PackageRela
(relPart == null ? "<null>" : relPart.getId()) + " for relationship: " + relPart);
}
relationshipsByID.put(relPart.getId(), relPart);
- relationshipsByType.put(relPart.getRelationshipType(), relPart);
}
/**
@@ -214,8 +208,8 @@ public final class PackageRelationshipCollection implements Iterable<PackageRela
*/
public PackageRelationship addRelationship(URI targetUri,
TargetMode targetMode, String relationshipType, String id) {
- if (id == null || id.length() == 0) {
- // Generate a unique ID is id parameter is null.
+ if (id == null || id.isEmpty()) {
+ // Generate a unique ID if id parameter is null.
if (nextRelationshipId == -1) {
nextRelationshipId = size() + 1;
}
@@ -245,7 +239,6 @@ public final class PackageRelationshipCollection implements Iterable<PackageRela
PackageRelationship rel = relationshipsByID.get(id);
if (rel != null) {
relationshipsByID.remove(rel.getId());
- relationshipsByType.values().remove(rel);
internalRelationshipsByTargetName.values().remove(rel);
}
}
@@ -277,6 +270,11 @@ public final class PackageRelationshipCollection implements Iterable<PackageRela
* @return The package relationship identified by the specified id.
*/
public PackageRelationship getRelationshipByID(String id) {
+ if (id == null) {
+ throw new IllegalArgumentException("Cannot read relationship, provided ID is empty: " + id +
+ ", having relationships: " + relationshipsByID.keySet());
+ }
+
return relationshipsByID.get(id);
}
@@ -418,7 +416,6 @@ public final class PackageRelationshipCollection implements Iterable<PackageRela
*/
public void clear() {
relationshipsByID.clear();
- relationshipsByType.clear();
internalRelationshipsByTargetName.clear();
}
diff --git a/test-data/slideshow/clusterfuzz-testcase-minimized-POIFuzzer-5205835528404992.pptx b/test-data/slideshow/clusterfuzz-testcase-minimized-POIFuzzer-5205835528404992.pptx
new file mode 100644
index 0000000000..41b48998e3
--- /dev/null
+++ b/test-data/slideshow/clusterfuzz-testcase-minimized-POIFuzzer-5205835528404992.pptx
Binary files differ
diff --git a/test-data/spreadsheet/stress.xls b/test-data/spreadsheet/stress.xls
index 21a3abea5c..5af5cc74d0 100644
--- a/test-data/spreadsheet/stress.xls
+++ b/test-data/spreadsheet/stress.xls
Binary files differ