[Patch] Skip XRef gaps in PDFDoc save methods
Submitted by Tobias Deiminger
Assigned to poppler-bugs
Link to original bug (#107057)
Description
Created attachment 140372 Skip XRef xrefEntryNone entries on incremental update and full rewrite
This patch aims to solve Okular bug https://bugs.kde.org/show_bug.cgi?id=395660. Actually there are several related problems, the patch fixes the easiest and sufficient part.
Currently, PDFDoc::saveIncrementalUpdate and saveCompleteRewrite iterate over the full continuous range of XRef::entries, ranging from object id 0 up to XRef::size. That seems problematic. The range may contain gaps (type == xrefEntryNone) which are merely details of popplers memory allocation, but don't contain objects from the PDF document. Hitting a gap with XRef::getEntry triggers "damaged file repair". It's implemented by XRef::constructXRef, and it makes things actually worse because constructXRef can't handle XRef streams nor objects from inside object streams. It wipes out formerly existing XRef information in that case.
The idea of this patch is to spare the gaps from iteration, and therefore avoid a bunch of consecutive faults early.
Atm. the patch is only tested for Okular test case. Poppler regression tests are yet outstanding.
Patch 140372, "Skip XRef xrefEntryNone entries on incremental update and full rewrite":
skip_xref_gaps.patch