[Poppler-bugs] [Bug 84722] New: Attribute::getName() returns wrong value for /N when UTF-16BE is used

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Mon Oct 6 10:26:29 PDT 2014


https://bugs.freedesktop.org/show_bug.cgi?id=84722

            Bug ID: 84722
           Summary: Attribute::getName()  returns wrong  value  for /N
                    when UTF-16BE is used
           Product: poppler
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: medium
         Component: general
          Assignee: poppler-bugs at lists.freedesktop.org
          Reporter: luigi.scarso at gmail.com

In the following pdf object 
/N has value 'elementname' encoded as UTF-16BE

19 0 obj
<< /K 18 0 R /S /div /Type /StructElem /A 
<< /P [ << 
/N <feff0065006c0065006d0065006e0074006e0061006d0065> 
/V <feff004100410041> >> ] /O /UserProperties >> /Pg 15 0 R /P 17 0 R >>
endobj

Attribute::getName() returns 0xfe 0xff 0x00..0x65 but the caller doesn't know
the size, so it uses only 0xfe 0xff 0x00.

I propose these patches: 
1) another constructor Attribute(const char *nameA, Object *valueA, int lenA)
2) a new method GooString *getUserPropertyName() to keep backwards
compatibility (getName() is in the public interface)
3) a patch to parseUserProperty






--- 0.26.4/poppler/StructElement.cc    2014-09-11 18:28:21.000000000 +0200
+++ p0.26.4/poppler/StructElement.cc        2014-10-06 09:13:31.013375479 +0200
@@ -690,6 +690,23 @@
   valueA->copy(&value);
 }

+Attribute::Attribute(const char *nameA, Object *valueA, int lenA):
+  type(UserProperty),
+  owner(UserProperties),
+  revision(0),
+  name(nameA,lenA),
+  value(),
+  hidden(gFalse),
+  formatted(NULL)
+{
+  assert(valueA);
+  valueA->copy(&value);
+}
+
+
+
+
+
 Attribute::Attribute(Type type, Object *valueA):
   type(type),
   owner(UserProperties), // TODO: Determine corresponding owner from Type
@@ -785,13 +802,17 @@
   return entry ? entry->type : Unknown;
 }

+
 Attribute *Attribute::parseUserProperty(Dict *property)
 {
   Object obj, value;
   const char *name = NULL;
+  int len = 0 ;

-  if (property->lookup("N", &obj)->isString())
+  if (property->lookup("N", &obj)->isString()){
     name = obj.getString()->getCString();
+    len = obj.getString()->getLength();
+  }
   else if (obj.isName())
     name = obj.getName();
   else {
@@ -807,7 +828,7 @@
     return NULL;
   }

-  Attribute *attribute = new Attribute(name, &value);
+  Attribute *attribute = new Attribute(name, &value,len) ;
   value.free();
   obj.free();



--- 0.26.4/poppler/StructElement.h     2014-09-11 18:28:20.000000000 +0200
+++ p0.26.4/poppler/StructElement.h 2014-10-06 09:13:53.469376410 +0200
@@ -76,6 +76,9 @@
   // Creates an UserProperty attribute, with an arbitrary name and value.
   Attribute(const char *name, Object *value);

+  // Creates an UserProperty attribute, with an arbitrary name of lenght len
and value.
+  Attribute(const char *name, Object *value, int len);
+
   GBool isOk() const { return type != Unknown; }

   // Name, type and value can be set only on construction.
@@ -87,6 +90,9 @@
   static Object *getDefaultValue(Type type);

   const char *getName() const { return type == UserProperty ?
name.getCString() : getTypeName(); }
+  GooString *getUserPropertyName() const { return type == UserProperty ?
name.copy() : NULL; }
+
+

   // The revision is optional, and defaults to zero.
   Guint getRevision() const { return revision; }

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/poppler-bugs/attachments/20141006/6c7cbb2a/attachment-0001.html>


More information about the Poppler-bugs mailing list