2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-29 00:10:54 +00:00

handle files with object 0 as a real object

git-svn-id: svn+q:///qpdf/trunk@1049 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2011-01-31 14:59:42 +00:00
parent 5ccc788b80
commit a8f2248729
6 changed files with 35 additions and 7 deletions

View File

@ -1,3 +1,16 @@
2011-01-31 Jay Berkenbilt <ejb@ql.org>
* libqpdf/QPDF.cc (readObjectAtOffset): use -1 rather than 0 when
reading an object at a given to indicate that no object number is
expected. This allows xref recovery to proceed even if a file
uses the invalid object number 0 as a regular object.
* libqpdf/QPDF_linearization.cc (isLinearized): use -1 rather than
0 as a sentintel for not having found the first object in the
file. Since -1 can never match the regular expression, this
prevents an infinite loop when checking a file that starts with
(erroneous) 0 0 obj. (Fixes qpdf-Bugs-3159950.)
2010-10-04 Jay Berkenbilt <ejb@ql.org> 2010-10-04 Jay Berkenbilt <ejb@ql.org>
* 2.2.2: release * 2.2.2: release

View File

@ -782,7 +782,7 @@ QPDF::read_xrefStream(off_t xref_offset)
try try
{ {
xref_obj = readObjectAtOffset( xref_obj = readObjectAtOffset(
false, xref_offset, "xref stream", 0, 0, xobj, xgen); false, xref_offset, "xref stream", -1, 0, xobj, xgen);
} }
catch (QPDFExc& e) catch (QPDFExc& e)
{ {
@ -1580,7 +1580,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
objid = atoi(tobjid.getValue().c_str()); objid = atoi(tobjid.getValue().c_str());
generation = atoi(tgen.getValue().c_str()); generation = atoi(tgen.getValue().c_str());
if (exp_objid && if ((exp_objid >= 0) &&
(! ((objid == exp_objid) && (generation == exp_generation)))) (! ((objid == exp_objid) && (generation == exp_generation))))
{ {
QTC::TC("qpdf", "QPDF err wrong objid/generation"); QTC::TC("qpdf", "QPDF err wrong objid/generation");
@ -1593,7 +1593,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
} }
catch (QPDFExc& e) catch (QPDFExc& e)
{ {
if (exp_objid && try_recovery && this->attempt_recovery) if ((exp_objid >= 0) && try_recovery && this->attempt_recovery)
{ {
// Try again after reconstructing xref table // Try again after reconstructing xref table
reconstruct_xref(e); reconstruct_xref(e);

View File

@ -95,9 +95,9 @@ QPDF::isLinearized()
static PCRE lindict_re("(?s:(\\d+)\\s+0\\s+obj\\s*<<)"); static PCRE lindict_re("(?s:(\\d+)\\s+0\\s+obj\\s*<<)");
off_t offset = -1; off_t offset = -1;
int lindict_obj = 0; int lindict_obj = -1;
char* p = buf; char* p = buf;
while (lindict_obj == 0) while (lindict_obj == -1)
{ {
PCRE::Match m(lindict_re.match(p)); PCRE::Match m(lindict_re.match(p));
if (m) if (m)
@ -312,7 +312,7 @@ QPDF::readHintStream(Pipeline& pl, off_t offset, size_t length)
int obj; int obj;
int gen; int gen;
QPDFObjectHandle H = readObjectAtOffset( QPDFObjectHandle H = readObjectAtOffset(
false, offset, "linearization hint stream", 0, 0, obj, gen); false, offset, "linearization hint stream", -1, 0, obj, gen);
ObjCache& oc = this->obj_cache[ObjGen(obj, gen)]; ObjCache& oc = this->obj_cache[ObjGen(obj, gen)];
off_t min_end_offset = oc.end_before_space; off_t min_end_offset = oc.end_before_space;
off_t max_end_offset = oc.end_after_space; off_t max_end_offset = oc.end_after_space;

View File

@ -111,7 +111,7 @@ $td->runtest("new stream",
show_ntests(); show_ntests();
# ---------- # ----------
$td->notify("--- Miscellaneous Tests ---"); $td->notify("--- Miscellaneous Tests ---");
$n_tests += 28; $n_tests += 29;
$td->runtest("qpdf version", $td->runtest("qpdf version",
{$td->COMMAND => "qpdf --version"}, {$td->COMMAND => "qpdf --version"},
@ -191,6 +191,14 @@ foreach my $file (qw(short-id long-id))
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);
} }
# Handle file with invalid xref table and object 0 as a regular object
# (bug 3159950).
$td->runtest("check obj0.pdf",
{$td->COMMAND => "qpdf --check obj0.pdf"},
{$td->FILE => "obj0-check.out",
$td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
# Min/Force version # Min/Force version
$td->runtest("set min version", $td->runtest("set min version",
{$td->COMMAND => "qpdf --min-version=1.6 good1.pdf a.pdf"}, {$td->COMMAND => "qpdf --min-version=1.6 good1.pdf a.pdf"},

View File

@ -0,0 +1,7 @@
checking obj0.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized
WARNING: obj0.pdf: file is damaged
WARNING: obj0.pdf (object 1 0, file position 77): expected n n obj
WARNING: obj0.pdf: Attempting to reconstruct cross-reference table

BIN
qpdf/qtest/qpdf/obj0.pdf Normal file

Binary file not shown.