mirror of
https://github.com/qpdf/qpdf.git
synced 2025-03-20 00:22:23 +00:00
Clarify intent in readObjectAtOffset
Rather than using object id -1 to mean "don't care", use object ID 0, and clarify the difference between that use and indication of a direct object.
This commit is contained in:
parent
9de29daba5
commit
6f1041afb8
@ -1060,7 +1060,7 @@ QPDF::read_xrefStream(qpdf_offset_t xref_offset)
|
|||||||
QPDFObjectHandle xref_obj;
|
QPDFObjectHandle xref_obj;
|
||||||
try {
|
try {
|
||||||
xref_obj = readObjectAtOffset(
|
xref_obj = readObjectAtOffset(
|
||||||
false, xref_offset, "xref stream", -1, 0, xobj, xgen);
|
false, xref_offset, "xref stream", 0, 0, xobj, xgen);
|
||||||
} catch (QPDFExc&) {
|
} catch (QPDFExc&) {
|
||||||
// ignore -- report error below
|
// ignore -- report error below
|
||||||
}
|
}
|
||||||
@ -1782,10 +1782,25 @@ QPDF::readObjectAtOffset(
|
|||||||
int& objid,
|
int& objid,
|
||||||
int& generation)
|
int& generation)
|
||||||
{
|
{
|
||||||
|
bool check_og = true;
|
||||||
|
if (exp_objid == 0) {
|
||||||
|
// This method uses an expect object ID of 0 to indicate that
|
||||||
|
// we don't know or don't care what the actual object ID is at
|
||||||
|
// this offset. This is true when we read the xref stream and
|
||||||
|
// linearization hint streams. In this case, we don't verify
|
||||||
|
// the expect object ID/generation against what was read from
|
||||||
|
// the file. There is also no reason to attempt xref recovery
|
||||||
|
// if we get a failure in this case since the read attempt was
|
||||||
|
// not triggered by an xref lookup.
|
||||||
|
check_og = false;
|
||||||
|
try_recovery = false;
|
||||||
|
} else {
|
||||||
|
setLastObjectDescription(description, exp_objid, exp_generation);
|
||||||
|
}
|
||||||
|
|
||||||
if (!this->m->attempt_recovery) {
|
if (!this->m->attempt_recovery) {
|
||||||
try_recovery = false;
|
try_recovery = false;
|
||||||
}
|
}
|
||||||
setLastObjectDescription(description, exp_objid, exp_generation);
|
|
||||||
|
|
||||||
// Special case: if offset is 0, just return null. Some PDF
|
// Special case: if offset is 0, just return null. Some PDF
|
||||||
// writers, in particular "Mac OS X 10.7.5 Quartz PDFContext", may
|
// writers, in particular "Mac OS X 10.7.5 Quartz PDFContext", may
|
||||||
@ -1839,7 +1854,7 @@ QPDF::readObjectAtOffset(
|
|||||||
"object with ID 0");
|
"object with ID 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((exp_objid >= 0) &&
|
if (check_og &&
|
||||||
(!((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");
|
||||||
QPDFExc e(
|
QPDFExc e(
|
||||||
@ -1859,7 +1874,7 @@ QPDF::readObjectAtOffset(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (QPDFExc& e) {
|
} catch (QPDFExc& e) {
|
||||||
if ((exp_objid >= 0) && try_recovery) {
|
if (try_recovery) {
|
||||||
// Try again after reconstructing xref table
|
// Try again after reconstructing xref table
|
||||||
reconstruct_xref(e);
|
reconstruct_xref(e);
|
||||||
QPDFObjGen og(exp_objid, exp_generation);
|
QPDFObjGen og(exp_objid, exp_generation);
|
||||||
|
@ -328,7 +328,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length)
|
|||||||
int obj;
|
int obj;
|
||||||
int gen;
|
int gen;
|
||||||
QPDFObjectHandle H = readObjectAtOffset(
|
QPDFObjectHandle H = readObjectAtOffset(
|
||||||
false, offset, "linearization hint stream", -1, 0, obj, gen);
|
false, offset, "linearization hint stream", 0, 0, obj, gen);
|
||||||
ObjCache& oc = this->m->obj_cache[QPDFObjGen(obj, gen)];
|
ObjCache& oc = this->m->obj_cache[QPDFObjGen(obj, gen)];
|
||||||
qpdf_offset_t min_end_offset = oc.end_before_space;
|
qpdf_offset_t min_end_offset = oc.end_before_space;
|
||||||
qpdf_offset_t max_end_offset = oc.end_after_space;
|
qpdf_offset_t max_end_offset = oc.end_after_space;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user