Treat loop in xref tables as damage (fixes #192)

Prior to this fix, if there was a loop detected in following /Prev
pointers in xref streams/tables, it would cause qpdf to lose data.
Note that this condition causes many PDF readers to hang or fail.
This commit is contained in:
Jay Berkenbilt 2018-03-05 14:25:17 -05:00
parent 6fe1e9de40
commit ee44aef8d0
8 changed files with 1620 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2018-03-05 Jay Berkenbilt <ejb@ql.org>
* Improve handling of loops while following cross reference
tables. Fixes #192.
2018-03-04 Jay Berkenbilt <ejb@ql.org>
* 8.0.1: release

View File

@ -532,7 +532,9 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
}
if (visited.count(xref_offset) != 0)
{
xref_offset = 0;
QTC::TC("qpdf", "QPDF xref loop");
throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,
"loop detected following xref tables");
}
}

View File

@ -334,3 +334,4 @@ QPDFObjectHandle dictionary ignoring removereplace 0
QPDFObjectHandle numeric non-numeric 0
QPDFObjectHandle erase array bounds 0
qpdf-c called qpdf_check_pdf 0
QPDF xref loop 0

View File

@ -1400,7 +1400,7 @@ $td->runtest("C API: no recovery",
show_ntests();
# ----------
$td->notify("--- Recovery Tests ---");
$n_tests += @badfiles + 7;
$n_tests += @badfiles + 9;
# Recovery tests. These are mostly after-the-fact -- when recovery
# was implemented, some degree of recovery was possible on many of the
@ -1469,6 +1469,17 @@ $td->runtest("recoverable xref errors",
$td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
$td->runtest("xref loop with append",
{$td->COMMAND =>
"qpdf --deterministic-id append-xref-loop.pdf a.pdf"},
{$td->FILE => "append-xref-loop.out",
$td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "append-xref-loop-fixed.pdf"});
show_ntests();
# ----------
$td->notify("--- Basic Parsing Tests ---");

Binary file not shown.

View File

@ -0,0 +1,4 @@
WARNING: append-xref-loop.pdf: file is damaged
WARNING: append-xref-loop.pdf: loop detected following xref tables
WARNING: append-xref-loop.pdf: Attempting to reconstruct cross-reference table
qpdf: operation succeeded with warnings; resulting file may have some problems

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +1,4 @@
WARNING: issue-149.pdf: reported number of objects (11) inconsistent with actual number of objects (7)
WARNING: issue-149.pdf: file is damaged
WARNING: issue-149.pdf: loop detected following xref tables
WARNING: issue-149.pdf: Attempting to reconstruct cross-reference table
qpdf: operation succeeded with warnings; resulting file may have some problems