diff --git a/src/main/java/org/sejda/sambox/input/XrefParser.java b/src/main/java/org/sejda/sambox/input/XrefParser.java index d6396a5c5..83b48b63d 100644 --- a/src/main/java/org/sejda/sambox/input/XrefParser.java +++ b/src/main/java/org/sejda/sambox/input/XrefParser.java @@ -88,7 +88,16 @@ void onTrailerFound(COSDictionary found) @Override void onEntryFound(XrefEntry entry) { - parser().provider().addEntryIfAbsent(entry); + if(entry.getByteOffset() < XrefEntry.UNKNOWN_OFFSET) + { + LOG.warn("Ignoring xrefEntry inUse with byteOffset: {}", entry); + } + else + { + parser().provider().addEntryIfAbsent(entry); + } + + } }; } diff --git a/src/test/java/org/sejda/sambox/input/PDFParserTest.java b/src/test/java/org/sejda/sambox/input/PDFParserTest.java index 1e50cf8c9..cacc694fa 100644 --- a/src/test/java/org/sejda/sambox/input/PDFParserTest.java +++ b/src/test/java/org/sejda/sambox/input/PDFParserTest.java @@ -512,6 +512,18 @@ public void testPDFBOX4372() throws IOException } } + @Test + public void testNegativeOffsetXrefEntry() throws IOException + { + try (PDDocument doc = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom( + getClass().getResourceAsStream("/sambox/test_multiple_xref_tables_negative_offset.pdf")))) + { + + PDFTextStripper textStripper = new PDFTextStripper(); + textStripper.getText(doc); + } + } + //https://lists.apache.org/thread/rmvn7t4bj4d8wsln722kdk39k4fc0ff7 @Test public void noLoopOrOOM() throws IOException