1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:17:34 +00:00

LibPDF: Try to repair XRef tables with broken indices

An XRef table usually starts with an object number of zero. While it
could technically start at any other number, this is a tell-tale sign
of a broken table.

For the "broken" documents I encountered, this always meant that some
objects must have been removed from the start of the table, without
updating the following indices. When this is the case, the document is
not able to be read normally.

However, most other PDF parsers seem to know of this quirk and fix the
XRef table automatically.

Likewise, we now check for this exact case, and if it matches up with
what we expect, we update the XRef table such that all object numbers
match the actual objects found in the file again.
This commit is contained in:
Julian Offenhäuser 2022-11-23 11:33:14 +01:00 committed by Andreas Kling
parent e06a065594
commit d1bc89e30b
3 changed files with 54 additions and 1 deletions

View file

@ -68,6 +68,8 @@ public:
m_entries.append(entry);
}
ALWAYS_INLINE Vector<XRefEntry>& entries() { return m_entries; }
[[nodiscard]] ALWAYS_INLINE bool has_object(size_t index) const
{
return index < m_entries.size() && m_entries[index].byte_offset != -1;