When a duplicate object is seen in an xref stream, only replace the object if it has a higher generation number (Issue #155)

This commit is contained in:
Michael R Sweet
2026-01-29 13:01:23 -05:00
parent c7bf1695fd
commit 2837cafd41
2 changed files with 18 additions and 11 deletions

View File

@@ -24,6 +24,7 @@ v1.6.2 - YYYY-MM-DD
- Added missing range checks to `pdfioArrayCopy` and `pdfioDictCopy`.
- Refactored PDF encryption code to fix unlocking with certain files.
- Improved xref table loop detection (Issue #148)
- Changed how duplicate objects are handled in PDF files (Issue #155)
- Fixed xref reconstruction for objects lacking a `Type` value.
- Fixed `pdfioPageOpenStream` for indirect `Contents` arrays.
- Fixed an error propagation bug when reading too-long values (Issue #146)

View File

@@ -2236,20 +2236,26 @@ load_xref(
// Create a placeholder for the object in memory...
if ((current = pdfioFileFindObj(pdf, (size_t)number)) != NULL)
{
PDFIO_DEBUG("load_xref: existing object, prev offset=%u\n", (unsigned)current->offset);
PDFIO_DEBUG("load_xref: existing object, prev offset=%u, generation=%u, new generation=%u\n", (unsigned)current->offset, (unsigned)current->generation, (unsigned)generation);
if (w[0] == 0 || buffer[0] == 1)
if (generation > current->generation)
{
// Location of object...
current->offset = (off_t)offset;
}
else if (number != offset)
{
// Object is part of a stream, offset is the object number...
current->offset = 0;
}
// Newer version of an existing object - update the references...
current->generation = generation;
PDFIO_DEBUG("load_xref: new offset=%u\n", (unsigned)current->offset);
if (w[0] == 0 || buffer[0] == 1)
{
// Location of object...
current->offset = (off_t)offset;
}
else if (number != offset)
{
// Object is part of a stream, offset is the object number...
current->offset = 0;
}
PDFIO_DEBUG("load_xref: new offset=%u\n", (unsigned)current->offset);
}
}
if (w[0] > 0 && buffer[0] == 2)