diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java index a321faf8f..e6a77f854 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java +++ b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java @@ -575,7 +575,8 @@ public class POIXMLDocumentPart { // Default to searching from 1, unless they asked for 0+ int idx = minIdx; if (minIdx < 0) idx = 1; - while (idx < 1000) { + int maxIdx = minIdx + pkg.getParts().size(); + while (idx <= maxIdx) { name = descriptor.getFileName(idx); PackagePartName ppName = PackagingURIHelper.createPartName(name); if (!pkg.containPart(ppName)) {