Skip to content

Commit 4c155a0

Browse files
committed
Fix issue with zero xref update.
1 parent e953694 commit 4c155a0

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

core/src/main/java/com/itextpdf/core/pdf/PdfReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ protected PdfDictionary readXrefSection() throws IOException {
936936
}
937937
PdfDictionary trailer = (PdfDictionary) readObject(false);
938938
PdfNumber xrefSize = (PdfNumber) trailer.get(PdfName.Size);
939-
if (xrefSize == null || xrefSize.getIntValue() != end) {
939+
if (xrefSize == null || (xrefSize.getIntValue() != end && end > 0)) {
940940
throw new PdfException(PdfException.InvalidXrefSection);
941941
}
942942

core/src/test/java/com/itextpdf/core/pdf/PdfReaderTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,28 @@ public void pdfVersionTest() throws IOException {
14721472
pdfDoc.close();
14731473
}
14741474

1475+
@Test
1476+
public void zeroUpdateTest() throws IOException {
1477+
String filename = sourceFolder + "stationery.pdf";
1478+
1479+
FileInputStream fis = new FileInputStream(filename);
1480+
PdfReader reader = new PdfReader(fis);
1481+
PdfDocument pdfDoc = new PdfDocument(reader);
1482+
1483+
// Test such construction:
1484+
// xref
1485+
// 0 0
1486+
// trailer
1487+
// <</Size 27/Root 1 0 R/Info 12 0 R//Prev 245232/XRefStm 244927>>
1488+
// startxref
1489+
1490+
Assert.assertFalse(reader.hasFixedXref());
1491+
Assert.assertFalse(reader.hasRebuiltXref());
1492+
1493+
pdfDoc.close();
1494+
}
1495+
1496+
14751497
private boolean objectTypeEqualTo(PdfObject object, PdfName type) {
14761498
PdfName objectType = ((PdfDictionary)object).getAsName(PdfName.Type);
14771499
return type.equals(objectType);
Binary file not shown.

0 commit comments

Comments
 (0)