[poppler] 2 commits - poppler/Lexer.cc poppler/Object.cc poppler/Object.h poppler/PDFDoc.cc poppler/PSOutputDev.cc poppler/SecurityHandler.cc poppler/StructElement.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Sat Nov 26 16:37:19 UTC 2016


 poppler/Lexer.cc           |    3 ++-
 poppler/Object.cc          |   15 +++++++++++++--
 poppler/Object.h           |   16 +++++++++++++---
 poppler/PDFDoc.cc          |   22 ++++++++++++++++------
 poppler/PSOutputDev.cc     |    5 +++--
 poppler/SecurityHandler.cc |    3 ++-
 poppler/StructElement.cc   |    5 +++--
 7 files changed, 52 insertions(+), 17 deletions(-)

New commits:
commit 628299bc02ef825609e1ade539f967bbf052be0c
Author: Jakub Alba <jakubalba at gmail.com>
Date:   Sun Jul 24 22:46:23 2016 +0200

    treat file identifier as a hex string, not a basic string

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 5f05388..9c09283 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -703,8 +703,8 @@ GBool PDFDoc::getID(GooString *permanent_id, GooString *update_id) {
     Object obj2;
 
     if (permanent_id) {
-      if (obj.arrayGet(0, &obj2)->isString()) {
-        if (!get_id (obj2.getString(), permanent_id)) {
+      if (obj.arrayGet(0, &obj2)->isHexString()) {
+        if (!get_id (obj2.getHexString(), permanent_id)) {
 	  obj2.free();
 	  return gFalse;
 	}
@@ -717,8 +717,8 @@ GBool PDFDoc::getID(GooString *permanent_id, GooString *update_id) {
     }
 
     if (update_id) {
-      if (obj.arrayGet(1, &obj2)->isString()) {
-        if (!get_id (obj2.getString(), update_id)) {
+      if (obj.arrayGet(1, &obj2)->isHexString()) {
+        if (!get_id (obj2.getHexString(), update_id)) {
 	  obj2.free();
 	  return gFalse;
 	}
@@ -1467,7 +1467,7 @@ Dict *PDFDoc::createTrailerDict(int uxrefSize, GBool incrUpdate, Goffset startxR
   //calculate md5 digest
   Guchar digest[16];
   md5((Guchar*)message.getCString(), message.getLength(), digest);
-  obj1.initString(new GooString((const char*)digest, 16));
+  obj1.initHexString(new GooString((const char*)digest, 16));
 
   //create ID array
   Object obj2,obj3,obj5;
@@ -1492,7 +1492,7 @@ Dict *PDFDoc::createTrailerDict(int uxrefSize, GBool incrUpdate, Goffset startxR
   } else {
     //new file => same values for the two identifiers
     obj2.arrayAdd(&obj1);
-    obj1.initString(new GooString((const char*)digest, 16));
+    obj1.initHexString(new GooString((const char*)digest, 16));
     obj2.arrayAdd(&obj1);
     trailerDict->set("ID", &obj2);
   }
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 9124c49..403bf02 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -31,6 +31,7 @@
 // Copyright (C) 2014 Till Kamppeter <till.kamppeter at gmail.com>
 // Copyright (C) 2015 Marek Kasik <mkasik at redhat.com>
 // Copyright (C) 2016 Caolán McNamara <caolanm at redhat.com>
+// Copyright (C) 2016 Jakub Alba <jakubalba at gmail.com>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -7100,8 +7101,8 @@ void PSOutputDev::opiBegin13(GfxState *state, Dict *dict) {
   obj1.free();
 
   dict->lookup("ID", &obj1);
-  if (obj1.isString()) {
-    writePSFmt("%ALDImageID: {0:t}\n", obj1.getString());
+  if (obj1.isHexString()) {
+    writePSFmt("%ALDImageID: {0:t}\n", obj1.getHexString());
   }
   obj1.free();
 
diff --git a/poppler/SecurityHandler.cc b/poppler/SecurityHandler.cc
index 9e0546e..2e165b6 100644
--- a/poppler/SecurityHandler.cc
+++ b/poppler/SecurityHandler.cc
@@ -17,6 +17,7 @@
 // Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2014 Fabio D'Urso <fabiodurso at hotmail.it>
 // Copyright (C) 2016 Alok Anand <alok4nand at gmail.com>
+// Copyright (C) 2016 Jakub Alba <jakubalba at gmail.com>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -275,7 +276,7 @@ StandardSecurityHandler::StandardSecurityHandler(PDFDoc *docA,
 	  encRevision >= 2 && encRevision <= 3) {
 	if (fileIDObj.isArray()) {
 	  if (fileIDObj.arrayGet(0, &fileIDObj1)->isString()) {
-	    fileID = fileIDObj1.getString()->copy();
+	    fileID = fileIDObj1.getHexString()->copy();
 	  } else {
 	    fileID = new GooString();
 	  }
diff --git a/poppler/StructElement.cc b/poppler/StructElement.cc
index c668820..a890465 100644
--- a/poppler/StructElement.cc
+++ b/poppler/StructElement.cc
@@ -8,6 +8,7 @@
 // Copyright 2014 Luigi Scarso <luigi.scarso at gmail.com>
 // Copyright 2014 Albert Astals Cid <aacid at kde.org>
 // Copyright 2015 Dmytro Morgun <lztoad at gmail.com>
+// Copyright 2016 Jakub Alba <jakubalba at gmail.com>
 //
 //========================================================================
 
@@ -1122,8 +1123,8 @@ void StructElement::parse(Dict *element)
   obj.free();
 
   // Object ID (optional), to be looked at the IDTree in the tree root.
-  if (element->lookup("ID", &obj)->isString()) {
-    s->id = obj.takeString();
+  if (element->lookup("ID", &obj)->isHexString()) {
+    s->id = obj.takeHexString();
   }
   obj.free();
 
commit debd1361f4a4cb7811677ab7a8f241b8b6fca5f9
Author: Jakub Alba <jakubalba at gmail.com>
Date:   Sun Jul 24 22:30:30 2016 +0200

    introduced hex string as a new Object type and used it for file identifier
    
    File identifiers are usually written as hex strings (and this is how the PDF
    reference presents them in an example). Until now, poppler was reading hex
    strings properly, but was forgeting about the fact that a given string is a hex
    string, so e.g. file identifier was first read as a hex string and then printed as
    an ordinary string and thanks to that what was printed was actually junk. This
    commit fixes that.

diff --git a/poppler/Lexer.cc b/poppler/Lexer.cc
index 952967a..a908edf 100644
--- a/poppler/Lexer.cc
+++ b/poppler/Lexer.cc
@@ -18,6 +18,7 @@
 // Copyright (C) 2010 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2012, 2013 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
+// Copyright (C) 2016 Jakub Alba <jakubalba at gmail.com>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -526,7 +527,7 @@ Object *Lexer::getObj(Object *obj, int objNum) {
 	s->append(tokBuf, n);
       if (m == 1)
 	s->append((char)(c2 << 4));
-      obj->initString(s);
+      obj->initHexString(s);
     }
     break;
 
diff --git a/poppler/Object.cc b/poppler/Object.cc
index d06bb39..0966e0d 100644
--- a/poppler/Object.cc
+++ b/poppler/Object.cc
@@ -15,6 +15,7 @@
 //
 // Copyright (C) 2008, 2010, 2012 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
+// Copyright (C) 2016 Jakub Alba <jakubalba at gmail.com>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -54,12 +55,13 @@ static const char *objTypeNames[numObjTypes] = {
   "error",
   "eof",
   "none",
-  "integer64"
+  "integer64",
+  "hexstring"
 };
 
 #ifdef DEBUG_MEM
 int Object::numAlloc[numObjTypes] =
-  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 #endif
 
 Object *Object::initArray(XRef *xref) {
@@ -91,6 +93,7 @@ Object *Object::copy(Object *obj) {
   *obj = *this;
   switch (type) {
   case objString:
+  case objHexString:
     obj->string = string->copy();
     break;
   case objName:
@@ -125,6 +128,7 @@ Object *Object::fetch(XRef *xref, Object *obj, int recursion) {
 void Object::free() {
   switch (type) {
   case objString:
+  case objHexString:
     delete string;
     break;
   case objName:
@@ -180,6 +184,13 @@ void Object::print(FILE *f) {
     fwrite(string->getCString(), 1, string->getLength(), f);
     fprintf(f, ")");
     break;
+  case objHexString:
+    fprintf(f, "<");
+    for (i = 0; i < string->getLength(); i++) {
+      fprintf(f, "%02x", string->getChar(i) & 0xff);
+    }
+    fprintf(f, ">");
+    break;
   case objName:
     fprintf(f, "/%s", name);
     break;
diff --git a/poppler/Object.h b/poppler/Object.h
index e3f8f37..21b9030 100644
--- a/poppler/Object.h
+++ b/poppler/Object.h
@@ -105,10 +105,12 @@ enum ObjType {
   objNone,			// uninitialized object
 
   // poppler-only objects
-  objInt64			// integer with at least 64-bits
+  objInt64,			// integer with at least 64-bits
+
+  objHexString			// hex string
 };
 
-#define numObjTypes 15		// total number of object types
+#define numObjTypes 16		// total number of object types
 
 //------------------------------------------------------------------------
 // Object
@@ -138,6 +140,8 @@ public:
     { initObj(objReal); real = realA; return this; }
   Object *initString(GooString *stringA)
     { initObj(objString); string = stringA; return this; }
+  Object *initHexString(GooString *hexA)
+    { initObj(objHexString); string = hexA; return this; }
   Object *initName(const char *nameA)
     { initObj(objName); name = copyString(nameA); return this; }
   Object *initNull()
@@ -178,6 +182,7 @@ public:
   GBool isReal() { return type == objReal; }
   GBool isNum() { return type == objInt || type == objReal || type == objInt64; }
   GBool isString() { return type == objString; }
+  GBool isHexString() { return type == objHexString; }
   GBool isName() { return type == objName; }
   GBool isNull() { return type == objNull; }
   GBool isArray() { return type == objArray; }
@@ -213,6 +218,11 @@ public:
   // because the object it's not expected to have a NULL string.
   GooString *takeString() {
     OBJECT_TYPE_CHECK(objString); GooString *s = string; string = NULL; return s; }
+  GooString *getHexString() { OBJECT_TYPE_CHECK(objHexString); return string; }
+  // After takeHexString() the only method that should be called for the object is free()
+  // because the object it's not expected to have a NULL hex string.
+  GooString *takeHexString() {
+    OBJECT_TYPE_CHECK(objHexString); GooString *s = string; string = NULL; return s; }
   char *getName() { OBJECT_TYPE_CHECK(objName); return name; }
   Array *getArray() { OBJECT_TYPE_CHECK(objArray); return array; }
   Dict *getDict() { OBJECT_TYPE_CHECK(objDict); return dict; }
@@ -271,7 +281,7 @@ private:
     int intg;			//   integer
     long long int64g;           //   64-bit integer
     double real;		//   real
-    GooString *string;		//   string
+    GooString *string;		//   (hex) string
     char *name;			//   name
     Array *array;		//   array
     Dict *dict;			//   dictionary
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index f28bdec..5f05388 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -1272,6 +1272,16 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, Guint numO
     case objString:
       writeString(obj->getString(), outStr, fileKey, encAlgorithm, keyLength, objNum, objGen);
       break;
+    case objHexString:
+    {
+      GooString *s = obj->getHexString();
+      outStr->printf("<");
+      for (int i = 0; i < s->getLength(); i++) {
+        outStr->printf("%02x", s->getChar(i) & 0xff);
+      }
+      outStr->printf(">");
+      break;
+    }
     case objName:
     {
       GooString name(obj->getName());


More information about the poppler mailing list