Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ private COSDictionary get(int pageNum, COSDictionary node, int encountered)
{
if (pageNum < 1)
{
pageSet.clear();
throw new IndexOutOfBoundsException("Index out of bounds: " + pageNum);
}
if (pageSet.contains(node))
Expand Down Expand Up @@ -357,10 +358,12 @@ private COSDictionary get(int pageNum, COSDictionary node, int encountered)
}
}

pageSet.clear();
throw new IllegalStateException("1-based index not found: " + pageNum);
}
else
{
pageSet.clear();
throw new IndexOutOfBoundsException("1-based index out of bounds: " + pageNum);
}
}
Expand All @@ -373,6 +376,7 @@ private COSDictionary get(int pageNum, COSDictionary node, int encountered)
}
else
{
pageSet.clear();
throw new IllegalStateException("1-based index not found: " + pageNum);
}
}
Expand Down
16 changes: 16 additions & 0 deletions pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;

Expand Down Expand Up @@ -133,6 +135,20 @@ void testInsertAfterBlankPage() throws IOException
}
}

@Test
void getValidPageAfterOutOfBoundsLookup() throws IOException
{
try (PDDocument document = new PDDocument())
{
PDPage page = new PDPage();
document.addPage(page);
PDPageTree pages = document.getPages();

assertThrows(IndexOutOfBoundsException.class, () -> pages.get(1));
assertSame(page.getCOSObject(), pages.get(0).getCOSObject());
}
}

/**
* PDFBOX-6040: avoid loop in getInheritableAttribute().
*
Expand Down