Skip to content

Commit

Permalink
Bug 66425: Avoid a NullPointerException found via oss-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 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
  • Loading branch information
centic9 committed Aug 24, 2023
1 parent e4ba982 commit cdb2ba1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ 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<>();


/**
Expand Down Expand Up @@ -195,7 +190,6 @@ public void addRelationship(PackageRelationship relPart) {
(relPart == null ? "<null>" : relPart.getId()) + " for relationship: " + relPart);
}
relationshipsByID.put(relPart.getId(), relPart);
relationshipsByType.put(relPart.getRelationshipType(), relPart);
}

/**
Expand All @@ -214,8 +208,8 @@ public void addRelationship(PackageRelationship relPart) {
*/
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;
}
Expand Down Expand Up @@ -245,7 +239,6 @@ public void removeRelationship(String id) {
PackageRelationship rel = relationshipsByID.get(id);
if (rel != null) {
relationshipsByID.remove(rel.getId());
relationshipsByType.values().remove(rel);
internalRelationshipsByTargetName.values().remove(rel);
}
}
Expand Down Expand Up @@ -277,6 +270,11 @@ public PackageRelationship getRelationship(int index) {
* @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);
}

Expand Down Expand Up @@ -418,7 +416,6 @@ public Iterator<PackageRelationship> iterator(String typeFilter) {
*/
public void clear() {
relationshipsByID.clear();
relationshipsByType.clear();
internalRelationshipsByTargetName.clear();
}

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

0 comments on commit cdb2ba1

Please sign in to comment.