diff --git a/libqpdf/QPDF_objects.cc b/libqpdf/QPDF_objects.cc index a834bddf..746c690d 100644 --- a/libqpdf/QPDF_objects.cc +++ b/libqpdf/QPDF_objects.cc @@ -1031,12 +1031,12 @@ Xref_table::insert(int obj, int f0, qpdf_offset_t f1, int f2) auto& entry = table[static_cast(obj)]; auto old_type = entry.type(); - if (!old_type && entry.gen() > 0) { + if ((!old_type && entry.gen() > 0) || (old_type && entry.gen() >= new_gen)) { // At the moment we are processing the updates last to first and therefore the gen doesn't - // matter as long as it > 0 to distinguish it from an uninitialized entry. This will need - // to be revisited when we want to support incremental updates or more comprehensive - // checking. - QTC::TC("qpdf", "QPDF xref deleted object"); + // matter for deleted objects as long as gen > 0 to distinguish it from an uninitialized + // entry. This will need to be revisited when we want to support incremental updates or more + // comprehensive checking. + QTC::TC("qpdf", "QPDF xref replaced / deleted object", old_type == 0 ? 0 : 1); return; } @@ -1046,11 +1046,6 @@ Xref_table::insert(int obj, int f0, qpdf_offset_t f1, int f2) return; } - if (old_type && entry.gen() >= new_gen) { - QTC::TC("qpdf", "QPDF xref reused object"); - return; - } - switch (f0) { case 1: // f2 is generation diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 6f8d5566..7c587f06 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -46,7 +46,6 @@ QPDFWriter write to file 0 QPDF lin write nshared_total > nshared_first_page 1 QPDFWriter encrypted hint stream 0 QPDF opt inherited scalar 0 -QPDF xref reused object 0 QPDF xref gen > 0 1 QPDF not a pdf file 0 QPDF can't find startxref 0 @@ -83,7 +82,7 @@ QPDF prev key in xref stream dictionary 0 QPDF prev key in trailer dictionary 0 QPDF found xref stream 0 QPDF ignoring XRefStm in trailer 0 -QPDF xref deleted object 0 +QPDF xref replaced / deleted object 1 SF_FlateLzwDecode PNG filter 0 QPDF xref /Index is null 0 QPDF xref /Index is array 1