Browse code

bb#11372 - finalize encrypted hex strings correctly

Kevin Lin authored on 2015/08/15 01:22:49
Showing 1 changed files
... ...
@@ -545,12 +545,27 @@ char *pdf_parse_string(struct pdf_struct *pdf, struct pdf_obj *obj, const char *
545 545
             return NULL;
546 546
         }
547 547
 
548
-        res = cli_calloc(1, (p2 - p1) + 2);
549
-        if (!(res))
550
-            return NULL;
551 548
 
552
-        strncpy(res, p1, (p2 - p1) + 1);
553
-        if (endchar)
549
+        res = pdf_finalize_string(pdf, obj, p1, (p2 - p1) + 1);
550
+        if (!res) {
551
+            res = cli_calloc(1, (p2 - p1) + 2);
552
+            if (!(res))
553
+                return NULL;
554
+            memcpy(res, p1, (p2 - p1) + 1);
555
+            res[(p2 - p1) + 1] = '\0';
556
+
557
+            if (meta) {
558
+                meta->length = (p2 - p1) + 1;
559
+                meta->obj = obj;
560
+                meta->success = 0;
561
+            }
562
+        } else if (meta) {
563
+            meta->length = strlen(res);
564
+            meta->obj = obj;
565
+            meta->success = 1;
566
+        }
567
+
568
+        if (res && endchar)
554 569
             *endchar = p2;
555 570
 
556 571
         return res;