From: Nick Burch Date: Fri, 10 Feb 2017 12:55:55 +0000 (+0000) Subject: If a property refers to an invalid index, log + ignore rather than failing with a... X-Git-Tag: REL_3_16_FINAL~105 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3eeab149c7e08d4e37f1c3adba5ef84b642d4abf;p=poi.git If a property refers to an invalid index, log + ignore rather than failing with a IndexOutOfBoundsException git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1782461 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/poifs/property/PropertyTableBase.java b/src/java/org/apache/poi/poifs/property/PropertyTableBase.java index 477cf036d8..82f57bf724 100644 --- a/src/java/org/apache/poi/poifs/property/PropertyTableBase.java +++ b/src/java/org/apache/poi/poifs/property/PropertyTableBase.java @@ -24,6 +24,8 @@ import java.util.Stack; import org.apache.poi.poifs.filesystem.BATManaged; import org.apache.poi.poifs.storage.HeaderBlock; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * This class embodies the Property Table for the filesystem, @@ -33,6 +35,9 @@ import org.apache.poi.poifs.storage.HeaderBlock; * for the different block schemes as needed. */ public abstract class PropertyTableBase implements BATManaged { + private static final POILogger _logger = + POILogFactory.getLogger(PropertyTableBase.class); + private final HeaderBlock _header_block; protected final List _properties; @@ -123,17 +128,28 @@ public abstract class PropertyTableBase implements BATManaged { populatePropertyTree(( DirectoryProperty ) property); } index = property.getPreviousChildIndex(); - if (Property.isValidIndex(index)) + if (isValidIndex(index)) { children.push(_properties.get(index)); } index = property.getNextChildIndex(); - if (Property.isValidIndex(index)) + if (isValidIndex(index)) { children.push(_properties.get(index)); } } } + + protected boolean isValidIndex(int index) { + if (! Property.isValidIndex(index)) + return false; + if (index < 0 || index >= _properties.size()) { + _logger.log(POILogger.WARN, "Property index " + index + + "outside the valid range 0.."+_properties.size()); + return false; + } + return true; + } /** * Get the start block for the property table