diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PersistPtrHolder.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PersistPtrHolder.java index db3482f0aad..29697716cfe 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PersistPtrHolder.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PersistPtrHolder.java @@ -127,7 +127,14 @@ protected PersistPtrHolder(byte[] source, int start, int len) { // Grab the offsets for each of the sheets for(int i=0; i new PersistPtrHolder(data, 0, data.length)); + } + + /** + * Equally important: the hardening must not introduce a new lower + * ceiling. Offsets up to {@link Integer#MAX_VALUE} are still + * representable as a signed int and must continue to parse - byte + * arrays in the JVM can be that large in principle, and downstream + * code already bounds-checks against the actual docstream length. + */ + @Test + void testAcceptsMaxIntSheetOffset() { + byte[] data = buildRecord(Integer.MAX_VALUE); + PersistPtrHolder ptr = new PersistPtrHolder(data, 0, data.length); + Integer offset = ptr.getSlideLocationsLookup().get(0); + assertEquals(Integer.MAX_VALUE, offset.intValue()); + } +}