Created attachment 121323 [details]
Mark holes in xref table as free entries
I've got downstream report with a PDF form which doesn't save entered data. I've looked at this in more detail and it seems that the problem is caused by reconstruction of xref table before saving of the form which causes "reset" of the form.
The reconstruction is performed because there is a call for XRef::getEntry() on entry which does not exist (with i = 7 btw). This entry doesn't exist because there is a hole in the xref table. I was not sure whether the table is correct then but from https://bugs.freedesktop.org/show_bug.cgi?id=48679 it seems that it is (and note 17 on section 3.4.3 in specification of PDF 1.7 says that we should treat such holes as free entries).
Attached is a patch which works for me but I'm not sure whether it doesn't add another bug elsewhere. It marks newly added entries which where not listed in previous sections of xref table as free. It doesn't do this if previous size of the xref table was 0 because this indicates that the PDF is probably linearized and it would mark some entries as free even if those will be populated later.
It doesn't "chain" the free entries but it seems that it work even without that (otherwise we would need to reuse the code from beginning of XRef::writeXRef() which does this).
The original report and the reproducer can be found here: https://bugzilla.redhat.com/show_bug.cgi?id=1301016
-- GitLab Migration Automatic Message --
This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.
You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/poppler/poppler/issues/483.