mirror of
https://github.com/qpdf/qpdf.git
synced 2025-02-02 11:58:25 +00:00
QPDFObjGen : tidy QPDF private methods
Change method signatures to use QPDFObjGen. Use QPDFObjGen methods where possible. Remove redundant QPDF::objGenToIndirect.
This commit is contained in:
parent
3404ca8ac8
commit
f7978db1f6
@ -815,9 +815,9 @@ class QPDF
|
||||
|
||||
private:
|
||||
static std::shared_ptr<QPDFObject>
|
||||
resolve(QPDF* qpdf, int objid, int generation)
|
||||
resolve(QPDF* qpdf, QPDFObjGen const& og)
|
||||
{
|
||||
return qpdf->resolve(objid, generation);
|
||||
return qpdf->resolve(og);
|
||||
}
|
||||
static bool
|
||||
objectChanged(
|
||||
@ -879,8 +879,7 @@ class QPDF
|
||||
static bool
|
||||
pipeStreamData(
|
||||
QPDF* qpdf,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
qpdf_offset_t offset,
|
||||
size_t length,
|
||||
QPDFObjectHandle dict,
|
||||
@ -889,8 +888,7 @@ class QPDF
|
||||
bool will_retry)
|
||||
{
|
||||
return qpdf->pipeStreamData(
|
||||
objid,
|
||||
generation,
|
||||
og,
|
||||
offset,
|
||||
length,
|
||||
dict,
|
||||
@ -959,8 +957,7 @@ class QPDF
|
||||
std::string user_password;
|
||||
std::string encryption_key;
|
||||
std::string cached_object_encryption_key;
|
||||
int cached_key_objid;
|
||||
int cached_key_generation;
|
||||
QPDFObjGen cached_key_og;
|
||||
bool user_password_matched;
|
||||
bool owner_password_matched;
|
||||
};
|
||||
@ -973,8 +970,7 @@ class QPDF
|
||||
ForeignStreamData(
|
||||
std::shared_ptr<EncryptionParameters> encp,
|
||||
std::shared_ptr<InputSource> file,
|
||||
int foreign_objid,
|
||||
int foreign_generation,
|
||||
QPDFObjGen const& foreign_og,
|
||||
qpdf_offset_t offset,
|
||||
size_t length,
|
||||
QPDFObjectHandle local_dict);
|
||||
@ -982,8 +978,7 @@ class QPDF
|
||||
private:
|
||||
std::shared_ptr<EncryptionParameters> encp;
|
||||
std::shared_ptr<InputSource> file;
|
||||
int foreign_objid;
|
||||
int foreign_generation;
|
||||
QPDFObjGen foreign_og;
|
||||
qpdf_offset_t offset;
|
||||
size_t length;
|
||||
QPDFObjectHandle local_dict;
|
||||
@ -1017,14 +1012,13 @@ class QPDF
|
||||
friend class QPDF;
|
||||
|
||||
public:
|
||||
StringDecrypter(QPDF* qpdf, int objid, int gen);
|
||||
StringDecrypter(QPDF* qpdf, QPDFObjGen const& og);
|
||||
virtual ~StringDecrypter() = default;
|
||||
virtual void decryptString(std::string& val);
|
||||
|
||||
private:
|
||||
QPDF* qpdf;
|
||||
int objid;
|
||||
int gen;
|
||||
QPDFObjGen og;
|
||||
};
|
||||
|
||||
class ResolveRecorder
|
||||
@ -1127,17 +1121,15 @@ class QPDF
|
||||
void insertXrefEntry(
|
||||
int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite = false);
|
||||
void setLastObjectDescription(
|
||||
std::string const& description, int objid, int generation);
|
||||
std::string const& description, QPDFObjGen const& og);
|
||||
QPDFObjectHandle readObject(
|
||||
std::shared_ptr<InputSource>,
|
||||
std::string const& description,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
bool in_object_stream);
|
||||
size_t recoverStreamLength(
|
||||
std::shared_ptr<InputSource> input,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
qpdf_offset_t stream_offset);
|
||||
QPDFTokenizer::Token
|
||||
readToken(std::shared_ptr<InputSource>, size_t max_len = 0);
|
||||
@ -1149,16 +1141,15 @@ class QPDF
|
||||
QPDFObjGen const& exp_og,
|
||||
QPDFObjGen& og);
|
||||
bool objectChanged(QPDFObjGen const& og, std::shared_ptr<QPDFObject>& oph);
|
||||
std::shared_ptr<QPDFObject> resolve(int objid, int generation);
|
||||
std::shared_ptr<QPDFObject> resolve(QPDFObjGen const& og);
|
||||
void resolveObjectsInStream(int obj_stream_number);
|
||||
void stopOnError(std::string const& message);
|
||||
QPDFObjectHandle reserveObjectIfNotExists(int objid, int gen);
|
||||
QPDFObjectHandle reserveStream(int objid, int gen);
|
||||
QPDFObjectHandle reserveObjectIfNotExists(QPDFObjGen const& og);
|
||||
QPDFObjectHandle reserveStream(QPDFObjGen const& og);
|
||||
|
||||
// Calls finish() on the pipeline when done but does not delete it
|
||||
bool pipeStreamData(
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
qpdf_offset_t offset,
|
||||
size_t length,
|
||||
QPDFObjectHandle dict,
|
||||
@ -1174,8 +1165,7 @@ class QPDF
|
||||
std::shared_ptr<QPDF::EncryptionParameters> encp,
|
||||
std::shared_ptr<InputSource> file,
|
||||
QPDF& qpdf_for_warning,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
qpdf_offset_t offset,
|
||||
size_t length,
|
||||
QPDFObjectHandle dict,
|
||||
@ -1228,10 +1218,9 @@ class QPDF
|
||||
void initializeEncryption();
|
||||
static std::string getKeyForObject(
|
||||
std::shared_ptr<EncryptionParameters> encp,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
bool use_aes);
|
||||
void decryptString(std::string&, int objid, int generation);
|
||||
void decryptString(std::string&, QPDFObjGen const& og);
|
||||
static std::string compute_encryption_key_from_password(
|
||||
std::string const& password, EncryptionData const& data);
|
||||
static std::string recover_encryption_key_with_password(
|
||||
@ -1245,8 +1234,7 @@ class QPDF
|
||||
std::shared_ptr<InputSource> file,
|
||||
QPDF& qpdf_for_warning,
|
||||
Pipeline*& pipeline,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
QPDFObjectHandle& stream_dict,
|
||||
std::vector<std::shared_ptr<Pipeline>>& heap);
|
||||
|
||||
@ -1569,7 +1557,6 @@ class QPDF
|
||||
void dumpHSharedObject();
|
||||
void dumpHGeneric(HGeneric&);
|
||||
qpdf_offset_t adjusted_offset(qpdf_offset_t offset);
|
||||
QPDFObjectHandle objGenToIndirect(QPDFObjGen const&);
|
||||
void
|
||||
calculateLinearizationData(std::map<int, int> const& object_stream_data);
|
||||
void pushOutlinesToPart(
|
||||
|
134
libqpdf/QPDF.cc
134
libqpdf/QPDF.cc
@ -113,15 +113,13 @@ namespace
|
||||
QPDF::ForeignStreamData::ForeignStreamData(
|
||||
std::shared_ptr<EncryptionParameters> encp,
|
||||
std::shared_ptr<InputSource> file,
|
||||
int foreign_objid,
|
||||
int foreign_generation,
|
||||
QPDFObjGen const& foreign_og,
|
||||
qpdf_offset_t offset,
|
||||
size_t length,
|
||||
QPDFObjectHandle local_dict) :
|
||||
encp(encp),
|
||||
file(file),
|
||||
foreign_objid(foreign_objid),
|
||||
foreign_generation(foreign_generation),
|
||||
foreign_og(foreign_og),
|
||||
offset(offset),
|
||||
length(length),
|
||||
local_dict(local_dict)
|
||||
@ -176,17 +174,16 @@ QPDF::CopiedStreamDataProvider::registerForeignStream(
|
||||
this->foreign_stream_data[local_og] = foreign_stream;
|
||||
}
|
||||
|
||||
QPDF::StringDecrypter::StringDecrypter(QPDF* qpdf, int objid, int gen) :
|
||||
QPDF::StringDecrypter::StringDecrypter(QPDF* qpdf, QPDFObjGen const& og) :
|
||||
qpdf(qpdf),
|
||||
objid(objid),
|
||||
gen(gen)
|
||||
og(og)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::StringDecrypter::decryptString(std::string& val)
|
||||
{
|
||||
qpdf->decryptString(val, objid, gen);
|
||||
qpdf->decryptString(val, og);
|
||||
}
|
||||
|
||||
std::string const&
|
||||
@ -205,8 +202,6 @@ QPDF::EncryptionParameters::EncryptionParameters() :
|
||||
cf_stream(e_none),
|
||||
cf_string(e_none),
|
||||
cf_file(e_none),
|
||||
cached_key_objid(0),
|
||||
cached_key_generation(0),
|
||||
user_password_matched(false),
|
||||
owner_password_matched(false)
|
||||
{
|
||||
@ -631,7 +626,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
|
||||
(!this->m->trailer.isInitialized()) &&
|
||||
(t1 == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "trailer"))) {
|
||||
QPDFObjectHandle t =
|
||||
readObject(this->m->file, "trailer", 0, 0, false);
|
||||
readObject(this->m->file, "trailer", QPDFObjGen(), false);
|
||||
if (!t.isDictionary()) {
|
||||
// Oh well. It was worth a try.
|
||||
} else {
|
||||
@ -969,7 +964,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
|
||||
|
||||
// Set offset to previous xref table if any
|
||||
QPDFObjectHandle cur_trailer =
|
||||
readObject(this->m->file, "trailer", 0, 0, false);
|
||||
readObject(this->m->file, "trailer", QPDFObjGen(), false);
|
||||
if (!cur_trailer.isDictionary()) {
|
||||
QTC::TC("qpdf", "QPDF missing trailer");
|
||||
throw QPDFExc(
|
||||
@ -1341,7 +1336,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite)
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this->m->xref_table[QPDFObjGen(obj, 0)] = QPDFXRefEntry(f0, f1, f2);
|
||||
this->m->xref_table[QPDFObjGen(obj)] = QPDFXRefEntry(f0, f1, f2);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -1362,7 +1357,7 @@ QPDF::showXRefTable()
|
||||
for (auto const& iter: this->m->xref_table) {
|
||||
QPDFObjGen const& og = iter.first;
|
||||
QPDFXRefEntry const& entry = iter.second;
|
||||
cout << og.getObj() << "/" << og.getGen() << ": ";
|
||||
cout << og.unparse('/') << ": ";
|
||||
switch (entry.getType()) {
|
||||
case 1:
|
||||
cout << "uncompressed; offset = " << entry.getOffset();
|
||||
@ -1478,18 +1473,17 @@ QPDF::getAllObjects()
|
||||
|
||||
void
|
||||
QPDF::setLastObjectDescription(
|
||||
std::string const& description, int objid, int generation)
|
||||
std::string const& description, QPDFObjGen const& og)
|
||||
{
|
||||
this->m->last_object_description.clear();
|
||||
if (!description.empty()) {
|
||||
this->m->last_object_description += description;
|
||||
if (objid > 0) {
|
||||
if (og.isIndirect()) {
|
||||
this->m->last_object_description += ": ";
|
||||
}
|
||||
}
|
||||
if (objid > 0) {
|
||||
this->m->last_object_description +=
|
||||
"object " + QPDFObjGen(objid, generation).unparse(' ');
|
||||
if (og.isIndirect()) {
|
||||
this->m->last_object_description += "object " + og.unparse(' ');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1497,19 +1491,17 @@ QPDFObjectHandle
|
||||
QPDF::readObject(
|
||||
std::shared_ptr<InputSource> input,
|
||||
std::string const& description,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
bool in_object_stream)
|
||||
{
|
||||
setLastObjectDescription(description, objid, generation);
|
||||
setLastObjectDescription(description, og);
|
||||
qpdf_offset_t offset = input->tell();
|
||||
|
||||
bool empty = false;
|
||||
std::shared_ptr<StringDecrypter> decrypter_ph;
|
||||
StringDecrypter* decrypter = 0;
|
||||
if (this->m->encp->encrypted && (!in_object_stream)) {
|
||||
decrypter_ph =
|
||||
std::make_shared<StringDecrypter>(this, objid, generation);
|
||||
decrypter_ph = std::make_shared<StringDecrypter>(this, og);
|
||||
decrypter = decrypter_ph.get();
|
||||
}
|
||||
QPDFObjectHandle object = QPDFObjectHandle::parse(
|
||||
@ -1651,18 +1643,13 @@ QPDF::readObject(
|
||||
} catch (QPDFExc& e) {
|
||||
if (this->m->attempt_recovery) {
|
||||
warn(e);
|
||||
length = recoverStreamLength(
|
||||
input, objid, generation, stream_offset);
|
||||
length = recoverStreamLength(input, og, stream_offset);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
object = QPDFObjectHandle::Factory::newStream(
|
||||
this,
|
||||
QPDFObjGen(objid, generation),
|
||||
object,
|
||||
stream_offset,
|
||||
length);
|
||||
this, og, object, stream_offset, length);
|
||||
} else {
|
||||
input->seek(cur_offset, SEEK_SET);
|
||||
}
|
||||
@ -1690,8 +1677,7 @@ QPDF::findEndstream()
|
||||
size_t
|
||||
QPDF::recoverStreamLength(
|
||||
std::shared_ptr<InputSource> input,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
qpdf_offset_t stream_offset)
|
||||
{
|
||||
// Try to reconstruct stream length by looking for
|
||||
@ -1716,11 +1702,10 @@ QPDF::recoverStreamLength(
|
||||
|
||||
if (length) {
|
||||
qpdf_offset_t this_obj_offset = 0;
|
||||
QPDFObjGen this_obj(0, 0);
|
||||
QPDFObjGen this_og;
|
||||
|
||||
// Make sure this is inside this object
|
||||
for (auto const& iter: this->m->xref_table) {
|
||||
QPDFObjGen const& og = iter.first;
|
||||
QPDFXRefEntry const& entry = iter.second;
|
||||
if (entry.getType() == 1) {
|
||||
qpdf_offset_t obj_offset = entry.getOffset();
|
||||
@ -1728,12 +1713,11 @@ QPDF::recoverStreamLength(
|
||||
((this_obj_offset == 0) ||
|
||||
(this_obj_offset > obj_offset))) {
|
||||
this_obj_offset = obj_offset;
|
||||
this_obj = og;
|
||||
this_og = iter.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this_obj_offset && (this_obj.getObj() == objid) &&
|
||||
(this_obj.getGen() == generation)) {
|
||||
if (this_obj_offset && (this_og == og)) {
|
||||
// Well, we found endstream\nendobj within the space
|
||||
// allowed for this object, so we're probably in good
|
||||
// shape.
|
||||
@ -1791,7 +1775,7 @@ QPDF::readObjectAtOffset(
|
||||
check_og = false;
|
||||
try_recovery = false;
|
||||
} else {
|
||||
setLastObjectDescription(description, exp_og.getObj(), exp_og.getGen());
|
||||
setLastObjectDescription(description, exp_og);
|
||||
}
|
||||
|
||||
if (!this->m->attempt_recovery) {
|
||||
@ -1895,8 +1879,7 @@ QPDF::readObjectAtOffset(
|
||||
}
|
||||
}
|
||||
|
||||
QPDFObjectHandle oh =
|
||||
readObject(this->m->file, description, og.getObj(), og.getGen(), false);
|
||||
QPDFObjectHandle oh = readObject(this->m->file, description, og, false);
|
||||
|
||||
if (!(readToken(this->m->file) ==
|
||||
QPDFTokenizer::Token(QPDFTokenizer::tt_word, "endobj"))) {
|
||||
@ -1972,12 +1955,11 @@ QPDF::objectChanged(QPDFObjGen const& og, std::shared_ptr<QPDFObject>& oph)
|
||||
}
|
||||
|
||||
std::shared_ptr<QPDFObject>
|
||||
QPDF::resolve(int objid, int generation)
|
||||
QPDF::resolve(QPDFObjGen const& og)
|
||||
{
|
||||
// Check object cache before checking xref table. This allows us
|
||||
// to insert things into the object cache that don't actually
|
||||
// exist in the file.
|
||||
QPDFObjGen og(objid, generation);
|
||||
if (this->m->resolving.count(og)) {
|
||||
// This can happen if an object references itself directly or
|
||||
// indirectly in some key that has to be resolved during
|
||||
@ -2131,13 +2113,13 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
|
||||
// xref table and only cache what would actually be resolved here.
|
||||
for (auto const& iter: offsets) {
|
||||
int obj = iter.first;
|
||||
QPDFObjGen og(obj, 0);
|
||||
QPDFObjGen og(obj);
|
||||
QPDFXRefEntry const& entry = this->m->xref_table[og];
|
||||
if ((entry.getType() == 2) &&
|
||||
(entry.getObjStreamNumber() == obj_stream_number)) {
|
||||
int offset = iter.second;
|
||||
input->seek(offset, SEEK_SET);
|
||||
QPDFObjectHandle oh = readObject(input, "", obj, 0, true);
|
||||
QPDFObjectHandle oh = readObject(input, "", og, true);
|
||||
this->m->obj_cache[og] = ObjCache(
|
||||
QPDFObjectHandle::ObjAccessor::getObject(oh),
|
||||
end_before_space,
|
||||
@ -2163,21 +2145,20 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh)
|
||||
}
|
||||
|
||||
QPDFObjectHandle
|
||||
QPDF::reserveObjectIfNotExists(int objid, int gen)
|
||||
QPDF::reserveObjectIfNotExists(QPDFObjGen const& og)
|
||||
{
|
||||
QPDFObjGen og(objid, gen);
|
||||
if ((!this->m->obj_cache.count(og)) && (!this->m->xref_table.count(og))) {
|
||||
resolve(objid, gen);
|
||||
replaceObject(objid, gen, QPDFObjectHandle::Factory::makeReserved());
|
||||
resolve(og);
|
||||
replaceObject(og, QPDFObjectHandle::Factory::makeReserved());
|
||||
}
|
||||
return getObjectByID(objid, gen);
|
||||
return getObjectByObjGen(og);
|
||||
}
|
||||
|
||||
QPDFObjectHandle
|
||||
QPDF::reserveStream(int objid, int gen)
|
||||
QPDF::reserveStream(QPDFObjGen const& og)
|
||||
{
|
||||
return QPDFObjectHandle::Factory::newStream(
|
||||
this, QPDFObjGen(objid, gen), QPDFObjectHandle::newDictionary(), 0, 0);
|
||||
this, og, QPDFObjectHandle::newDictionary(), 0, 0);
|
||||
}
|
||||
|
||||
QPDFObjectHandle
|
||||
@ -2193,13 +2174,13 @@ QPDF::getObjectByID(int objid, int generation)
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh)
|
||||
QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh)
|
||||
{
|
||||
replaceObject(og.getObj(), og.getGen(), oh);
|
||||
replaceObject(QPDFObjGen(objid, generation), oh);
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh)
|
||||
QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh)
|
||||
{
|
||||
if (oh.isIndirect()) {
|
||||
QTC::TC("qpdf", "QPDF replaceObject called with indirect object");
|
||||
@ -2208,10 +2189,9 @@ QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh)
|
||||
}
|
||||
|
||||
// Force new object to appear in the cache
|
||||
resolve(objid, generation);
|
||||
resolve(og);
|
||||
|
||||
// Replace the object in the object cache
|
||||
QPDFObjGen og(objid, generation);
|
||||
this->m->ever_replaced_objects = true;
|
||||
this->m->obj_cache[og] =
|
||||
ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);
|
||||
@ -2511,8 +2491,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign)
|
||||
auto foreign_stream_data = std::make_shared<ForeignStreamData>(
|
||||
foreign_stream_qpdf->m->encp,
|
||||
foreign_stream_qpdf->m->file,
|
||||
foreign.getObjectID(),
|
||||
foreign.getGeneration(),
|
||||
foreign.getObjGen(),
|
||||
stream->getOffset(),
|
||||
stream->getLength(),
|
||||
dict);
|
||||
@ -2526,20 +2505,19 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign)
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2)
|
||||
QPDF::swapObjects(int objid1, int generation1, int objid2, int generation2)
|
||||
{
|
||||
swapObjects(og1.getObj(), og1.getGen(), og2.getObj(), og2.getGen());
|
||||
swapObjects(
|
||||
QPDFObjGen(objid1, generation1), QPDFObjGen(objid2, generation2));
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::swapObjects(int objid1, int generation1, int objid2, int generation2)
|
||||
QPDF::swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2)
|
||||
{
|
||||
// Force objects to be loaded into cache; then swap them in the
|
||||
// cache.
|
||||
resolve(objid1, generation1);
|
||||
resolve(objid2, generation2);
|
||||
QPDFObjGen og1(objid1, generation1);
|
||||
QPDFObjGen og2(objid2, generation2);
|
||||
resolve(og1);
|
||||
resolve(og2);
|
||||
ObjCache t = this->m->obj_cache[og1];
|
||||
this->m->ever_replaced_objects = true;
|
||||
this->m->obj_cache[og1] = this->m->obj_cache[og2];
|
||||
@ -2723,8 +2701,7 @@ QPDF::pipeStreamData(
|
||||
std::shared_ptr<EncryptionParameters> encp,
|
||||
std::shared_ptr<InputSource> file,
|
||||
QPDF& qpdf_for_warning,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
qpdf_offset_t offset,
|
||||
size_t length,
|
||||
QPDFObjectHandle stream_dict,
|
||||
@ -2735,14 +2712,7 @@ QPDF::pipeStreamData(
|
||||
std::vector<std::shared_ptr<Pipeline>> to_delete;
|
||||
if (encp->encrypted) {
|
||||
decryptStream(
|
||||
encp,
|
||||
file,
|
||||
qpdf_for_warning,
|
||||
pipeline,
|
||||
objid,
|
||||
generation,
|
||||
stream_dict,
|
||||
to_delete);
|
||||
encp, file, qpdf_for_warning, pipeline, og, stream_dict, to_delete);
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
@ -2780,8 +2750,7 @@ QPDF::pipeStreamData(
|
||||
"",
|
||||
file->getLastOffset(),
|
||||
("error decoding stream data for object " +
|
||||
QPDFObjGen(objid, generation).unparse(' ') + ": " +
|
||||
e.what())));
|
||||
og.unparse(' ') + ": " + e.what())));
|
||||
if (will_retry) {
|
||||
qpdf_for_warning.warn(
|
||||
// line-break
|
||||
@ -2807,8 +2776,7 @@ QPDF::pipeStreamData(
|
||||
|
||||
bool
|
||||
QPDF::pipeStreamData(
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
qpdf_offset_t offset,
|
||||
size_t length,
|
||||
QPDFObjectHandle stream_dict,
|
||||
@ -2820,8 +2788,7 @@ QPDF::pipeStreamData(
|
||||
this->m->encp,
|
||||
this->m->file,
|
||||
*this,
|
||||
objid,
|
||||
generation,
|
||||
og,
|
||||
offset,
|
||||
length,
|
||||
stream_dict,
|
||||
@ -2844,8 +2811,7 @@ QPDF::pipeForeignStreamData(
|
||||
foreign->encp,
|
||||
foreign->file,
|
||||
*this,
|
||||
foreign->foreign_objid,
|
||||
foreign->foreign_generation,
|
||||
foreign->foreign_og,
|
||||
foreign->offset,
|
||||
foreign->length,
|
||||
foreign->local_dict,
|
||||
|
@ -3098,7 +3098,7 @@ QPDFObjectHandle::dereference()
|
||||
}
|
||||
if (this->obj.get() == 0) {
|
||||
std::shared_ptr<QPDFObject> obj =
|
||||
QPDF::Resolver::resolve(this->qpdf, getObjectID(), getGeneration());
|
||||
QPDF::Resolver::resolve(this->qpdf, getObjGen());
|
||||
if (obj.get() == 0) {
|
||||
// QPDF::resolve never returns an uninitialized object, but
|
||||
// check just in case.
|
||||
|
@ -658,8 +658,7 @@ QPDF_Stream::pipeStreamData(
|
||||
QTC::TC("qpdf", "QPDF_Stream pipe original stream data");
|
||||
if (!QPDF::Pipe::pipeStreamData(
|
||||
this->qpdf,
|
||||
this->objid,
|
||||
this->generation,
|
||||
QPDFObjGen(this->objid, this->generation),
|
||||
this->offset,
|
||||
this->length,
|
||||
this->stream_dict,
|
||||
|
@ -1075,8 +1075,7 @@ QPDF::initializeEncryption()
|
||||
std::string
|
||||
QPDF::getKeyForObject(
|
||||
std::shared_ptr<EncryptionParameters> encp,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
bool use_aes)
|
||||
{
|
||||
if (!encp->encrypted) {
|
||||
@ -1084,26 +1083,24 @@ QPDF::getKeyForObject(
|
||||
"request for encryption key in non-encrypted PDF");
|
||||
}
|
||||
|
||||
if (!((objid == encp->cached_key_objid) &&
|
||||
(generation == encp->cached_key_generation))) {
|
||||
if (og != encp->cached_key_og) {
|
||||
encp->cached_object_encryption_key = compute_data_key(
|
||||
encp->encryption_key,
|
||||
objid,
|
||||
generation,
|
||||
og.getObj(),
|
||||
og.getGen(),
|
||||
use_aes,
|
||||
encp->encryption_V,
|
||||
encp->encryption_R);
|
||||
encp->cached_key_objid = objid;
|
||||
encp->cached_key_generation = generation;
|
||||
encp->cached_key_og = og;
|
||||
}
|
||||
|
||||
return encp->cached_object_encryption_key;
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::decryptString(std::string& str, int objid, int generation)
|
||||
QPDF::decryptString(std::string& str, QPDFObjGen const& og)
|
||||
{
|
||||
if (objid == 0) {
|
||||
if (!og.isIndirect()) {
|
||||
return;
|
||||
}
|
||||
bool use_aes = false;
|
||||
@ -1139,8 +1136,7 @@ QPDF::decryptString(std::string& str, int objid, int generation)
|
||||
}
|
||||
}
|
||||
|
||||
std::string key =
|
||||
getKeyForObject(this->m->encp, objid, generation, use_aes);
|
||||
std::string key = getKeyForObject(this->m->encp, og, use_aes);
|
||||
try {
|
||||
if (use_aes) {
|
||||
QTC::TC("qpdf", "QPDF_encryption aes decode string");
|
||||
@ -1175,8 +1171,8 @@ QPDF::decryptString(std::string& str, int objid, int generation)
|
||||
this->m->file->getName(),
|
||||
this->m->last_object_description,
|
||||
this->m->file->getLastOffset(),
|
||||
"error decrypting string for object " +
|
||||
QPDFObjGen(objid, generation).unparse() + ": " + e.what());
|
||||
"error decrypting string for object " + og.unparse() + ": " +
|
||||
e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1186,8 +1182,7 @@ QPDF::decryptStream(
|
||||
std::shared_ptr<InputSource> file,
|
||||
QPDF& qpdf_for_warning,
|
||||
Pipeline*& pipeline,
|
||||
int objid,
|
||||
int generation,
|
||||
QPDFObjGen const& og,
|
||||
QPDFObjectHandle& stream_dict,
|
||||
std::vector<std::shared_ptr<Pipeline>>& heap)
|
||||
{
|
||||
@ -1282,7 +1277,7 @@ QPDF::decryptStream(
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string key = getKeyForObject(encp, objid, generation, use_aes);
|
||||
std::string key = getKeyForObject(encp, og, use_aes);
|
||||
std::shared_ptr<Pipeline> new_pipeline;
|
||||
if (use_aes) {
|
||||
QTC::TC("qpdf", "QPDF_encryption aes decode stream");
|
||||
|
@ -371,9 +371,10 @@ QPDF::JSONReactor::containerEnd(JSON const& value)
|
||||
QPDFObjectHandle
|
||||
QPDF::JSONReactor::reserveObject(int obj, int gen)
|
||||
{
|
||||
auto oh = pdf.reserveObjectIfNotExists(obj, gen);
|
||||
QPDFObjGen og(obj, gen);
|
||||
auto oh = pdf.reserveObjectIfNotExists(og);
|
||||
if (oh.isReserved()) {
|
||||
this->reserved.insert(QPDFObjGen(obj, gen));
|
||||
this->reserved.insert(og);
|
||||
}
|
||||
return oh;
|
||||
}
|
||||
@ -495,8 +496,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
|
||||
QTC::TC("qpdf", "QPDF_json updating existing stream");
|
||||
} else {
|
||||
this->this_stream_needs_data = true;
|
||||
replacement =
|
||||
pdf.reserveStream(tos.getObjectID(), tos.getGeneration());
|
||||
replacement = pdf.reserveStream(tos.getObjGen());
|
||||
replaceObject(tos, replacement, value);
|
||||
}
|
||||
} else {
|
||||
|
@ -706,7 +706,7 @@ QPDF::getUncompressedObject(
|
||||
return obj;
|
||||
} else {
|
||||
int repl = (*(object_stream_data.find(obj.getObjectID()))).second;
|
||||
return objGenToIndirect(QPDFObjGen(repl, 0));
|
||||
return getObjectByObjGen(QPDFObjGen(repl));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1143,12 +1143,6 @@ QPDF::dumpHGeneric(HGeneric& t)
|
||||
<< "group_length: " << t.group_length << "\n";
|
||||
}
|
||||
|
||||
QPDFObjectHandle
|
||||
QPDF::objGenToIndirect(QPDFObjGen const& og)
|
||||
{
|
||||
return getObjectByID(og.getObj(), og.getGen());
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||
{
|
||||
@ -1387,9 +1381,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||
stopOnError("found other than one root while"
|
||||
" calculating linearization data");
|
||||
}
|
||||
this->m->part4.push_back(objGenToIndirect(*(lc_root.begin())));
|
||||
this->m->part4.push_back(getObjectByObjGen(*(lc_root.begin())));
|
||||
for (auto const& og: lc_open_document) {
|
||||
this->m->part4.push_back(objGenToIndirect(og));
|
||||
this->m->part4.push_back(getObjectByObjGen(og));
|
||||
}
|
||||
|
||||
// Part 6: first page objects. Note: implementation note 124
|
||||
@ -1418,11 +1412,11 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||
// hint tables.
|
||||
|
||||
for (auto const& og: lc_first_page_private) {
|
||||
this->m->part6.push_back(objGenToIndirect(og));
|
||||
this->m->part6.push_back(getObjectByObjGen(og));
|
||||
}
|
||||
|
||||
for (auto const& og: lc_first_page_shared) {
|
||||
this->m->part6.push_back(objGenToIndirect(og));
|
||||
this->m->part6.push_back(getObjectByObjGen(og));
|
||||
}
|
||||
|
||||
// Place the outline dictionary if it goes in the first page section.
|
||||
@ -1468,7 +1462,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||
for (auto const& og: this->m->obj_user_to_objects[ou]) {
|
||||
if (lc_other_page_private.count(og)) {
|
||||
lc_other_page_private.erase(og);
|
||||
this->m->part7.push_back(objGenToIndirect(og));
|
||||
this->m->part7.push_back(getObjectByObjGen(og));
|
||||
++this->m->c_page_offset_data.entries.at(i).nobjects;
|
||||
}
|
||||
}
|
||||
@ -1485,7 +1479,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||
|
||||
// Order is unimportant.
|
||||
for (auto const& og: lc_other_page_shared) {
|
||||
this->m->part8.push_back(objGenToIndirect(og));
|
||||
this->m->part8.push_back(getObjectByObjGen(og));
|
||||
}
|
||||
|
||||
// Part 9: other objects
|
||||
@ -1507,7 +1501,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||
for (auto const& og: pages_ogs) {
|
||||
if (lc_other.count(og)) {
|
||||
lc_other.erase(og);
|
||||
this->m->part9.push_back(objGenToIndirect(og));
|
||||
this->m->part9.push_back(getObjectByObjGen(og));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1537,7 +1531,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||
for (auto const& og: ogs) {
|
||||
if (lc_thumbnail_private.count(og)) {
|
||||
lc_thumbnail_private.erase(og);
|
||||
this->m->part9.push_back(objGenToIndirect(og));
|
||||
this->m->part9.push_back(getObjectByObjGen(og));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1550,7 +1544,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||
|
||||
// Place shared thumbnail objects
|
||||
for (auto const& og: lc_thumbnail_shared) {
|
||||
this->m->part9.push_back(objGenToIndirect(og));
|
||||
this->m->part9.push_back(getObjectByObjGen(og));
|
||||
}
|
||||
|
||||
// Place outlines unless in first page
|
||||
@ -1560,7 +1554,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||
|
||||
// Place all remaining objects
|
||||
for (auto const& og: lc_other) {
|
||||
this->m->part9.push_back(objGenToIndirect(og));
|
||||
this->m->part9.push_back(getObjectByObjGen(og));
|
||||
}
|
||||
|
||||
// Make sure we got everything exactly once.
|
||||
@ -1662,7 +1656,7 @@ QPDF::pushOutlinesToPart(
|
||||
lc_outlines.erase(outlines_og);
|
||||
part.push_back(outlines);
|
||||
for (auto const& og: lc_outlines) {
|
||||
part.push_back(objGenToIndirect(og));
|
||||
part.push_back(getObjectByObjGen(og));
|
||||
++this->m->c_outline_data.nobjects;
|
||||
}
|
||||
}
|
||||
|
@ -252,9 +252,7 @@ QPDF::pushInheritedAttributesToPageInternal(
|
||||
if ((warn_skipped_keys) && (cur_pages.hasKey("/Parent"))) {
|
||||
QTC::TC("qpdf", "QPDF unknown key not inherited");
|
||||
setLastObjectDescription(
|
||||
"Pages object",
|
||||
cur_pages.getObjectID(),
|
||||
cur_pages.getGeneration());
|
||||
"Pages object", cur_pages.getObjGen());
|
||||
warn(
|
||||
qpdf_e_pages,
|
||||
this->m->last_object_description,
|
||||
|
@ -207,8 +207,7 @@ QPDF::insertPageobjToPage(
|
||||
// that causes this to happen.
|
||||
setLastObjectDescription(
|
||||
"page " + QUtil::int_to_string(pos) + " (numbered from zero)",
|
||||
og.getObj(),
|
||||
og.getGen());
|
||||
og);
|
||||
throw QPDFExc(
|
||||
qpdf_e_pages,
|
||||
this->m->file->getName(),
|
||||
@ -334,7 +333,7 @@ QPDF::findPage(QPDFObjGen const& og)
|
||||
auto it = this->m->pageobj_to_pages_pos.find(og);
|
||||
if (it == this->m->pageobj_to_pages_pos.end()) {
|
||||
QTC::TC("qpdf", "QPDF_pages findPage not found");
|
||||
setLastObjectDescription("page object", og.getObj(), og.getGen());
|
||||
setLastObjectDescription("page object", og);
|
||||
throw QPDFExc(
|
||||
qpdf_e_pages,
|
||||
this->m->file->getName(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user