poppler/Decrypt.cc | 30 ++++++++++++------------- poppler/Decrypt.h | 8 +++--- poppler/PDFDoc.cc | 62 +++++++++++++++++++++++++++++------------------------ poppler/PDFDoc.h | 15 ++++++++---- poppler/Parser.cc | 4 +-- poppler/XRef.cc | 5 ++++ poppler/XRef.h | 1 7 files changed, 71 insertions(+), 54 deletions(-)
New commits: commit d70f77ee6a1bdee8b17f08f3066c0cd685853d21 Author: Albert Astals Cid <[email protected]> Date: Tue Aug 13 10:55:09 2019 +0200 Decrypt: take a Ref instead of two int diff --git a/poppler/Decrypt.cc b/poppler/Decrypt.cc index 16476f4f..6d9c14f2 100644 --- a/poppler/Decrypt.cc +++ b/poppler/Decrypt.cc @@ -305,7 +305,7 @@ bool Decrypt::makeFileKey2(int encVersion, int encRevision, int keyLength, //------------------------------------------------------------------------ BaseCryptStream::BaseCryptStream(Stream *strA, const unsigned char *fileKey, CryptAlgorithm algoA, - int keyLength, int objNum, int objGen): + int keyLength, Ref refA): FilterStream(strA) { algo = algoA; @@ -321,11 +321,11 @@ BaseCryptStream::BaseCryptStream(Stream *strA, const unsigned char *fileKey, Cry switch (algo) { case cryptRC4: if (likely(keyLength < static_cast<int>(sizeof(objKey) - 4))) { - objKey[keyLength] = objNum & 0xff; - objKey[keyLength + 1] = (objNum >> 8) & 0xff; - objKey[keyLength + 2] = (objNum >> 16) & 0xff; - objKey[keyLength + 3] = objGen & 0xff; - objKey[keyLength + 4] = (objGen >> 8) & 0xff; + objKey[keyLength] = refA.num & 0xff; + objKey[keyLength + 1] = (refA.num >> 8) & 0xff; + objKey[keyLength + 2] = (refA.num >> 16) & 0xff; + objKey[keyLength + 3] = refA.gen & 0xff; + objKey[keyLength + 4] = (refA.gen >> 8) & 0xff; md5(objKey, keyLength + 5, objKey); } if ((objKeyLength = keyLength + 5) > 16) { @@ -333,11 +333,11 @@ BaseCryptStream::BaseCryptStream(Stream *strA, const unsigned char *fileKey, Cry } break; case cryptAES: - objKey[keyLength] = objNum & 0xff; - objKey[keyLength + 1] = (objNum >> 8) & 0xff; - objKey[keyLength + 2] = (objNum >> 16) & 0xff; - objKey[keyLength + 3] = objGen & 0xff; - objKey[keyLength + 4] = (objGen >> 8) & 0xff; + objKey[keyLength] = refA.num & 0xff; + objKey[keyLength + 1] = (refA.num >> 8) & 0xff; + objKey[keyLength + 2] = (refA.num >> 16) & 0xff; + objKey[keyLength + 3] = refA.gen & 0xff; + objKey[keyLength + 4] = (refA.gen >> 8) & 0xff; objKey[keyLength + 5] = 0x73; // 's' objKey[keyLength + 6] = 0x41; // 'A' objKey[keyLength + 7] = 0x6c; // 'l' @@ -397,8 +397,8 @@ void BaseCryptStream::setAutoDelete(bool val) { //------------------------------------------------------------------------ EncryptStream::EncryptStream(Stream *strA, const unsigned char *fileKey, CryptAlgorithm algoA, - int keyLength, int objNum, int objGen): - BaseCryptStream(strA, fileKey, algoA, keyLength, objNum, objGen) + int keyLength, Ref refA): + BaseCryptStream(strA, fileKey, algoA, keyLength, refA) { // Fill the CBC initialization vector for AES and AES-256 switch (algo) { @@ -489,8 +489,8 @@ int EncryptStream::lookChar() { //------------------------------------------------------------------------ DecryptStream::DecryptStream(Stream *strA, const unsigned char *fileKey, CryptAlgorithm algoA, - int keyLength, int objNum, int objGen): - BaseCryptStream(strA, fileKey, algoA, keyLength, objNum, objGen) + int keyLength, Ref refA): + BaseCryptStream(strA, fileKey, algoA, keyLength, refA) { } diff --git a/poppler/Decrypt.h b/poppler/Decrypt.h index d4667c8c..fbd135fc 100644 --- a/poppler/Decrypt.h +++ b/poppler/Decrypt.h @@ -17,7 +17,7 @@ // Copyright (C) 2009 David Benjamin <[email protected]> // Copyright (C) 2012 Fabio D'Urso <[email protected]> // Copyright (C) 2013 Adrian Johnson <[email protected]> -// Copyright (C) 2013, 2018 Albert Astals Cid <[email protected]> +// Copyright (C) 2013, 2018, 2019 Albert Astals Cid <[email protected]> // Copyright (C) 2013 Thomas Freitag <[email protected]> // // To see a description of the changes please see the Changelog file that @@ -99,7 +99,7 @@ class BaseCryptStream : public FilterStream { public: BaseCryptStream(Stream *strA, const unsigned char *fileKey, CryptAlgorithm algoA, - int keyLength, int objNum, int objGen); + int keyLength, Ref ref); ~BaseCryptStream(); StreamKind getKind() override { return strCrypt; } void reset() override; @@ -133,7 +133,7 @@ class EncryptStream : public BaseCryptStream { public: EncryptStream(Stream *strA, const unsigned char *fileKey, CryptAlgorithm algoA, - int keyLength, int objNum, int objGen); + int keyLength, Ref ref); ~EncryptStream(); void reset() override; int lookChar() override; @@ -143,7 +143,7 @@ class DecryptStream : public BaseCryptStream { public: DecryptStream(Stream *strA, const unsigned char *fileKey, CryptAlgorithm algoA, - int keyLength, int objNum, int objGen); + int keyLength, Ref ref); ~DecryptStream(); void reset() override; int lookChar() override; diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc index aafba58d..dd619c62 100644 --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -1308,7 +1308,7 @@ void PDFDoc::writeString (const GooString* s, OutStream* outStr, const unsigned GooString *sEnc = nullptr; if (fileKey) { EncryptStream *enc = new EncryptStream(new MemStream(s->c_str(), 0, s->getLength(), Object(objNull)), - fileKey, encAlgorithm, keyLength, ref.num, ref.gen); + fileKey, encAlgorithm, keyLength, ref); sEnc = new GooString(); int c; enc->reset(); @@ -1440,12 +1440,12 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i } } if (removeFilter) { - encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); + encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref); encStream->setAutoDelete(false); stream = encStream; } } else { - encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); + encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref); encStream->setAutoDelete(false); stream = encStream; } @@ -1453,7 +1453,7 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i removeFilter = false; } } else if (fileKey != nullptr) { // Encrypt stream - encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); + encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref); encStream->setAutoDelete(false); stream = encStream; } @@ -1476,7 +1476,7 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i writeStream (stream,outStr); delete encStream; } else if (fileKey != nullptr && stream->getKind() == strFile && static_cast<FileStream*>(stream)->getNeedsEncryptionOnSave()) { - EncryptStream *encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); + EncryptStream *encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref); encStream->setAutoDelete(false); writeDictionnary (encStream->getDict(), outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, ref, alreadyWrittenDicts); writeStream (encStream, outStr); diff --git a/poppler/Parser.cc b/poppler/Parser.cc index 0cb1f7fb..db839de8 100644 --- a/poppler/Parser.cc +++ b/poppler/Parser.cc @@ -172,7 +172,7 @@ Object Parser::getObj(bool simpleOnly, s2 = new GooString(); decrypt = new DecryptStream(new MemStream(s->c_str(), 0, s->getLength(), Object(objNull)), fileKey, encAlgorithm, keyLength, - objNum, objGen); + {objNum, objGen}); decrypt->reset(); while ((c = decrypt->getChar()) != EOF) { s2->append((char)c); @@ -294,7 +294,7 @@ Stream *Parser::makeStream(Object &&dict, unsigned char *fileKey, // handle decryption if (fileKey) { str = new DecryptStream(str, fileKey, encAlgorithm, keyLength, - objNum, objGen); + {objNum, objGen}); } // get filters commit 242c53687ef5f685bb39fcc2b07d34f1443d2c75 Author: Albert Astals Cid <[email protected]> Date: Tue Aug 13 10:51:47 2019 +0200 PDFDoc: Add some overloads that take a Ref instead of two int diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc index dfb1ac58..aafba58d 100644 --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -1127,7 +1127,7 @@ void PDFDoc::saveIncrementalUpdate (OutStream* outStr) if (xref->getEntry(i)->type != xrefEntryFree) { Object obj1 = xref->fetch(ref, 1 /* recursion */); Goffset offset = writeObjectHeader(&ref, outStr); - writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); + writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref); writeObjectFooter(outStr); uxref->add(ref, offset, true); } else { @@ -1209,7 +1209,7 @@ void PDFDoc::saveCompleteRewrite (OutStream* outStr) if (xref->getEntry(i)->getFlag(XRefEntry::Unencrypted)) { writeObject(&obj1, outStr, nullptr, cryptRC4, 0, 0, 0); } else { - writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); + writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref); } writeObjectFooter(outStr); uxref->add(ref, offset, true); @@ -1218,7 +1218,7 @@ void PDFDoc::saveCompleteRewrite (OutStream* outStr) ref.gen = 0; //compressed entries have gen == 0 Object obj1 = xref->fetch(ref, 1 /* recursion */); Goffset offset = writeObjectHeader(&ref, outStr); - writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); + writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref); writeObjectFooter(outStr); uxref->add(ref, offset, true); } @@ -1231,7 +1231,7 @@ void PDFDoc::saveCompleteRewrite (OutStream* outStr) } void PDFDoc::writeDictionnary (Dict* dict, OutStream* outStr, XRef *xRef, unsigned int numOffset, unsigned char *fileKey, - CryptAlgorithm encAlgorithm, int keyLength, int objNum, int objGen, std::set<Dict*> *alreadyWrittenDicts) + CryptAlgorithm encAlgorithm, int keyLength, Ref ref, std::set<Dict*> *alreadyWrittenDicts) { bool deleteSet = false; if (!alreadyWrittenDicts) { @@ -1254,7 +1254,7 @@ void PDFDoc::writeDictionnary (Dict* dict, OutStream* outStr, XRef *xRef, unsign outStr->printf("/%s ", keyNameToPrint->c_str()); delete keyNameToPrint; Object obj1 = dict->getValNF(i).copy(); - writeObject(&obj1, outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen, alreadyWrittenDicts); + writeObject(&obj1, outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, ref, alreadyWrittenDicts); } outStr->printf(">> "); @@ -1302,13 +1302,13 @@ void PDFDoc::writeRawStream (Stream* str, OutStream* outStr) } void PDFDoc::writeString (const GooString* s, OutStream* outStr, const unsigned char *fileKey, - CryptAlgorithm encAlgorithm, int keyLength, int objNum, int objGen) + CryptAlgorithm encAlgorithm, int keyLength, Ref ref) { // Encrypt string if encryption is enabled GooString *sEnc = nullptr; if (fileKey) { EncryptStream *enc = new EncryptStream(new MemStream(s->c_str(), 0, s->getLength(), Object(objNull)), - fileKey, encAlgorithm, keyLength, objNum, objGen); + fileKey, encAlgorithm, keyLength, ref.num, ref.gen); sEnc = new GooString(); int c; enc->reset(); @@ -1366,6 +1366,12 @@ Goffset PDFDoc::writeObjectHeader (Ref *ref, OutStream* outStr) void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned int numOffset, unsigned char *fileKey, CryptAlgorithm encAlgorithm, int keyLength, int objNum, int objGen, std::set<Dict*> *alreadyWrittenDicts) { + writeObject(obj, outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, {objNum, objGen}, alreadyWrittenDicts); +} + +void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned int numOffset, unsigned char *fileKey, + CryptAlgorithm encAlgorithm, int keyLength, Ref ref, std::set<Dict*> *alreadyWrittenDicts) +{ Array *array; switch (obj->getType()) { @@ -1386,7 +1392,7 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i break; } case objString: - writeString(obj->getString(), outStr, fileKey, encAlgorithm, keyLength, objNum, objGen); + writeString(obj->getString(), outStr, fileKey, encAlgorithm, keyLength, ref); break; case objName: { @@ -1404,12 +1410,12 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i outStr->printf("["); for (int i=0; i<array->getLength(); i++) { Object obj1 = array->getNF(i).copy(); - writeObject(&obj1, outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen); + writeObject(&obj1, outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, ref); } outStr->printf("] "); break; case objDict: - writeDictionnary (obj->getDict(), outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen, alreadyWrittenDicts); + writeDictionnary (obj->getDict(), outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, ref, alreadyWrittenDicts); break; case objStream: { @@ -1434,12 +1440,12 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i } } if (removeFilter) { - encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, objNum, objGen); + encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); encStream->setAutoDelete(false); stream = encStream; } } else { - encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, objNum, objGen); + encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); encStream->setAutoDelete(false); stream = encStream; } @@ -1447,7 +1453,7 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i removeFilter = false; } } else if (fileKey != nullptr) { // Encrypt stream - encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, objNum, objGen); + encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); encStream->setAutoDelete(false); stream = encStream; } @@ -1466,13 +1472,13 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i } stream->getDict()->remove("DecodeParms"); - writeDictionnary (stream->getDict(),outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen, alreadyWrittenDicts); + writeDictionnary (stream->getDict(),outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, ref, alreadyWrittenDicts); writeStream (stream,outStr); delete encStream; } else if (fileKey != nullptr && stream->getKind() == strFile && static_cast<FileStream*>(stream)->getNeedsEncryptionOnSave()) { - EncryptStream *encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, objNum, objGen); + EncryptStream *encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); encStream->setAutoDelete(false); - writeDictionnary (encStream->getDict(), outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen, alreadyWrittenDicts); + writeDictionnary (encStream->getDict(), outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, ref, alreadyWrittenDicts); writeStream (encStream, outStr); delete encStream; } else { @@ -1488,7 +1494,7 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i } } } - writeDictionnary (stream->getDict(), outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen, alreadyWrittenDicts); + writeDictionnary (stream->getDict(), outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, ref, alreadyWrittenDicts); writeRawStream (stream, outStr); } break; @@ -1609,7 +1615,7 @@ void PDFDoc::writeXRefTableTrailer(Object &&trailerDict, XRef *uxref, bool write { uxref->writeTableToFile( outStr, writeAllEntries ); outStr->printf( "trailer\r\n"); - writeDictionnary(trailerDict.getDict(), outStr, xRef, 0, nullptr, cryptRC4, 0, 0, 0, nullptr); + writeDictionnary(trailerDict.getDict(), outStr, xRef, 0, nullptr, cryptRC4, 0, {0, 0}, nullptr); outStr->printf( "\r\nstartxref\r\n"); outStr->printf( "%lli\r\n", uxrefOffset); outStr->printf( "%%%%EOF\r\n"); @@ -1949,7 +1955,7 @@ unsigned int PDFDoc::writePageObjects(OutStream *outStr, XRef *xRef, unsigned in } else if (xRef->getEntry(n)->getFlag(XRefEntry::Unencrypted)) { writeObject(&obj, outStr, nullptr, cryptRC4, 0, 0, 0); } else { - writeObject(&obj, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); + writeObject(&obj, outStr, fileKey, encAlgorithm, keyLength, ref); } writeObjectFooter(outStr); xRef->add(ref, offset, true); diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h index 3c62903a..ba64296e 100644 --- a/poppler/PDFDoc.h +++ b/poppler/PDFDoc.h @@ -338,6 +338,8 @@ public: unsigned int writePageObjects(OutStream *outStr, XRef *xRef, unsigned int numOffset, bool combine = false); static void writeObject (Object *obj, OutStream* outStr, XRef *xref, unsigned int numOffset, unsigned char *fileKey, CryptAlgorithm encAlgorithm, int keyLength, int objNum, int objGen, std::set<Dict*> *alreadyWrittenDicts = nullptr); + static void writeObject (Object *obj, OutStream* outStr, XRef *xref, unsigned int numOffset, unsigned char *fileKey, + CryptAlgorithm encAlgorithm, int keyLength, Ref ref, std::set<Dict*> *alreadyWrittenDicts = nullptr); static void writeHeader(OutStream *outStr, int major, int minor); static Object createTrailerDict (int uxrefSize, bool incrUpdate, Goffset startxRef, @@ -352,21 +354,24 @@ private: void markDictionnary (Dict* dict, XRef *xRef, XRef *countRef, unsigned int numOffset, int oldRefNum, int newRefNum, std::set<Dict*> *alreadyMarkedDicts); void markObject (Object *obj, XRef *xRef, XRef *countRef, unsigned int numOffset, int oldRefNum, int newRefNum, std::set<Dict*> *alreadyMarkedDicts = nullptr); static void writeDictionnary (Dict* dict, OutStream* outStr, XRef *xRef, unsigned int numOffset, unsigned char *fileKey, - CryptAlgorithm encAlgorithm, int keyLength, int objNum, int objGen, std::set<Dict*> *alreadyWrittenDicts); + CryptAlgorithm encAlgorithm, int keyLength, Ref ref, std::set<Dict*> *alreadyWrittenDicts); // Write object header to current file stream and return its offset static Goffset writeObjectHeader (Ref *ref, OutStream* outStr); static void writeObjectFooter (OutStream* outStr); - void writeObject (Object *obj, OutStream* outStr, unsigned char *fileKey, CryptAlgorithm encAlgorithm, - int keyLength, int objNum, int objGen, std::set<Dict*> *alreadyWrittenDicts = nullptr) - { writeObject(obj, outStr, getXRef(), 0, fileKey, encAlgorithm, keyLength, objNum, objGen, alreadyWrittenDicts); } + inline void writeObject (Object *obj, OutStream* outStr, unsigned char *fileKey, CryptAlgorithm encAlgorithm, + int keyLength, int objNum, int objGen) + { writeObject(obj, outStr, getXRef(), 0, fileKey, encAlgorithm, keyLength, {objNum, objGen}); } + inline void writeObject (Object *obj, OutStream* outStr, unsigned char *fileKey, CryptAlgorithm encAlgorithm, + int keyLength, Ref ref) + { writeObject(obj, outStr, getXRef(), 0, fileKey, encAlgorithm, keyLength, ref); } static void writeStream (Stream* str, OutStream* outStr); static void writeRawStream (Stream* str, OutStream* outStr); void writeXRefTableTrailer (Goffset uxrefOffset, XRef *uxref, bool writeAllEntries, int uxrefSize, OutStream* outStr, bool incrUpdate); static void writeString (const GooString* s, OutStream* outStr, const unsigned char *fileKey, - CryptAlgorithm encAlgorithm, int keyLength, int objNum, int objGen); + CryptAlgorithm encAlgorithm, int keyLength, Ref ref); void saveIncrementalUpdate (OutStream* outStr); void saveCompleteRewrite (OutStream* outStr); commit 3a4a593146e614c31628f9327b2bc1320ac8caa5 Author: Albert Astals Cid <[email protected]> Date: Tue Aug 13 10:25:09 2019 +0200 XRef: add XRef::add overload that takes a Ref diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc index ab4abcad..dfb1ac58 100644 --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -927,7 +927,7 @@ int PDFDoc::savePageAs(const GooString *name, int pageNo) Dict *trailerDict = trailerObj->getDict(); const Object &ref = trailerDict->lookupNF("Info"); if (ref.isRef()) { - yRef->add(ref.getRef().num, ref.getRef().gen, 0, true); + yRef->add(ref.getRef(), 0, true); if (getXRef()->getEntry(ref.getRef().num)->type == xrefEntryCompressed) { yRef->getEntry(ref.getRef().num)->type = xrefEntryCompressed; } @@ -1129,9 +1129,9 @@ void PDFDoc::saveIncrementalUpdate (OutStream* outStr) Goffset offset = writeObjectHeader(&ref, outStr); writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); writeObjectFooter(outStr); - uxref->add(ref.num, ref.gen, offset, true); + uxref->add(ref, offset, true); } else { - uxref->add(ref.num, ref.gen, 0, false); + uxref->add(ref, 0, false); } } } @@ -1157,7 +1157,7 @@ void PDFDoc::saveIncrementalUpdate (OutStream* outStr) // Append an entry for the xref stream itself uxrefStreamRef.num = numobjects++; uxrefStreamRef.gen = 0; - uxref->add(uxrefStreamRef.num, uxrefStreamRef.gen, uxrefOffset, true); + uxref->add(uxrefStreamRef, uxrefOffset, true); } Object trailerDict = createTrailerDict(numobjects, true, getStartXRef(), &rootRef, getXRef(), fileNameA, uxrefOffset); @@ -1194,12 +1194,12 @@ void PDFDoc::saveCompleteRewrite (OutStream* outStr) /* the XRef class adds a lot of irrelevant free entries, we only want the significant one and we don't want the one with num=0 because it has already been added (gen = 65535)*/ if (ref.gen > 0 && ref.num > 0) - uxref->add(ref.num, ref.gen, 0, false); + uxref->add(ref, 0, false); } else if (xref->getEntry(i)->getFlag(XRefEntry::DontRewrite)) { // This entry must not be written, put a free entry instead (with incremented gen) ref.num = i; ref.gen = xref->getEntry(i)->gen + 1; - uxref->add(ref.num, ref.gen, 0, false); + uxref->add(ref, 0, false); } else if (type == xrefEntryUncompressed){ ref.num = i; ref.gen = xref->getEntry(i)->gen; @@ -1212,7 +1212,7 @@ void PDFDoc::saveCompleteRewrite (OutStream* outStr) writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); } writeObjectFooter(outStr); - uxref->add(ref.num, ref.gen, offset, true); + uxref->add(ref, offset, true); } else if (type == xrefEntryCompressed) { ref.num = i; ref.gen = 0; //compressed entries have gen == 0 @@ -1220,7 +1220,7 @@ void PDFDoc::saveCompleteRewrite (OutStream* outStr) Goffset offset = writeObjectHeader(&ref, outStr); writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); writeObjectFooter(outStr); - uxref->add(ref.num, ref.gen, offset, true); + uxref->add(ref, offset, true); } } xref->unlock(); @@ -1952,7 +1952,7 @@ unsigned int PDFDoc::writePageObjects(OutStream *outStr, XRef *xRef, unsigned in writeObject(&obj, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen); } writeObjectFooter(outStr); - xRef->add(ref.num, ref.gen, offset, true); + xRef->add(ref, offset, true); } } return objectsCount; diff --git a/poppler/XRef.cc b/poppler/XRef.cc index 87a08c7d..22ce7f9b 100644 --- a/poppler/XRef.cc +++ b/poppler/XRef.cc @@ -1264,6 +1264,11 @@ int XRef::getNumEntry(Goffset offset) else return -1; } +void XRef::add(Ref ref, Goffset offs, bool used) +{ + add(ref.num, ref.gen, offs, used); +} + void XRef::add(int num, int gen, Goffset offs, bool used) { xrefLocker(); if (num >= size) { diff --git a/poppler/XRef.h b/poppler/XRef.h index eb8684d3..fc5c8388 100644 --- a/poppler/XRef.h +++ b/poppler/XRef.h @@ -193,6 +193,7 @@ public: Ref addIndirectObject (const Object* o); void removeIndirectObject(Ref r); void add(int num, int gen, Goffset offs, bool used); + void add(Ref ref, Goffset offs, bool used); // Output XRef table to stream void writeTableToFile(OutStream* outStr, bool writeAllEntries); _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
