mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-04 03:10:52 +00:00
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:
parent
6fe1e9de40
commit
ee44aef8d0
|
@ -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>
|
2018-03-04 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* 8.0.1: release
|
* 8.0.1: release
|
||||||
|
|
|
@ -532,7 +532,9 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
|
||||||
}
|
}
|
||||||
if (visited.count(xref_offset) != 0)
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -334,3 +334,4 @@ QPDFObjectHandle dictionary ignoring removereplace 0
|
||||||
QPDFObjectHandle numeric non-numeric 0
|
QPDFObjectHandle numeric non-numeric 0
|
||||||
QPDFObjectHandle erase array bounds 0
|
QPDFObjectHandle erase array bounds 0
|
||||||
qpdf-c called qpdf_check_pdf 0
|
qpdf-c called qpdf_check_pdf 0
|
||||||
|
QPDF xref loop 0
|
||||||
|
|
|
@ -1400,7 +1400,7 @@ $td->runtest("C API: no recovery",
|
||||||
show_ntests();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Recovery Tests ---");
|
$td->notify("--- Recovery Tests ---");
|
||||||
$n_tests += @badfiles + 7;
|
$n_tests += @badfiles + 9;
|
||||||
|
|
||||||
# Recovery tests. These are mostly after-the-fact -- when recovery
|
# Recovery tests. These are mostly after-the-fact -- when recovery
|
||||||
# was implemented, some degree of recovery was possible on many of the
|
# 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->EXIT_STATUS => 3},
|
||||||
$td->NORMALIZE_NEWLINES);
|
$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();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Basic Parsing Tests ---");
|
$td->notify("--- Basic Parsing Tests ---");
|
||||||
|
|
BIN
qpdf/qtest/qpdf/append-xref-loop-fixed.pdf
Normal file
BIN
qpdf/qtest/qpdf/append-xref-loop-fixed.pdf
Normal file
Binary file not shown.
4
qpdf/qtest/qpdf/append-xref-loop.out
Normal file
4
qpdf/qtest/qpdf/append-xref-loop.out
Normal 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
|
1592
qpdf/qtest/qpdf/append-xref-loop.pdf
Normal file
1592
qpdf/qtest/qpdf/append-xref-loop.pdf
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -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
|
qpdf: operation succeeded with warnings; resulting file may have some problems
|
||||||
|
|
Loading…
Reference in New Issue
Block a user