Browse code

Add to the array linked list in the right order, rather than reversed.

Shawn Webb authored on 2014/06/24 23:43:15
Showing 2 changed files
... ...
@@ -3213,6 +3213,12 @@ static struct pdf_array *pdf_parse_array(struct pdf_struct *pdf, struct pdf_obj
3213 3213
 
3214 3214
         switch (begin[0]) {
3215 3215
             case '<':
3216
+                if (begin - objstart < objsz - 2 && begin[1] == '<') {
3217
+                    /* Handle dictionaries later */
3218
+                    break;
3219
+                }
3220
+
3221
+                /* Not a dictionary. Intentially fall through. */
3216 3222
             case '(':
3217 3223
                 val = pdf_parse_string(pdf, obj, begin, objsz, NULL);
3218 3224
                 break;
... ...
@@ -3241,7 +3247,7 @@ static struct pdf_array *pdf_parse_array(struct pdf_struct *pdf, struct pdf_obj
3241 3241
             break;
3242 3242
 
3243 3243
         if (!(node)) {
3244
-            res->nodes = node = calloc(1, sizeof(struct pdf_array_node));
3244
+            res->nodes = res->tail = node = calloc(1, sizeof(struct pdf_array_node));
3245 3245
             if (!(node))
3246 3246
                 break;
3247 3247
         } else {
... ...
@@ -3249,9 +3255,10 @@ static struct pdf_array *pdf_parse_array(struct pdf_struct *pdf, struct pdf_obj
3249 3249
             if (!(node))
3250 3250
                 break;
3251 3251
 
3252
-            node->next = res->nodes;
3253
-            res->nodes->prev = node;
3254
-            res->nodes = node;
3252
+            node->prev = res->tail;
3253
+            if (res->tail)
3254
+                res->tail->next = node;
3255
+            res->tail = node;
3255 3256
         }
3256 3257
 
3257 3258
         if (val != NULL) {
... ...
@@ -3293,6 +3300,19 @@ static void pdf_free_array(struct pdf_array *array)
3293 3293
     free(array);
3294 3294
 }
3295 3295
 
3296
+static void pdf_print_array(struct pdf_array *array, unsigned long depth)
3297
+{
3298
+    struct pdf_array_node *node;
3299
+    unsigned long i;
3300
+
3301
+    for (i=0, node = array->nodes; node != NULL; node = node->next, i++) {
3302
+        if (node->type == PDF_ARR_STRING)
3303
+            cli_errmsg("array[%lu][%lu]: %s\n", depth, i, (char *)(node->data));
3304
+        else
3305
+            pdf_print_array((struct pdf_array *)(node->data), depth+1);
3306
+    }
3307
+}
3308
+
3296 3309
 /* PDF statistics */
3297 3310
 static void ASCIIHexDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_action *act)
3298 3311
 {
... ...
@@ -3585,11 +3605,15 @@ static void Pages_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_act
3585 3585
     begin += 5;
3586 3586
 
3587 3587
     array = pdf_parse_array(pdf, obj, objsz, begin);
3588
-    if (array != NULL)
3589
-        for (node = array->nodes; node != NULL; node = node->next)
3590
-            if (node->datasz)
3591
-                if (((char *)(node->data))[0] == 'R')
3592
-                    npages++;
3588
+    if (!(array))
3589
+        return;
3590
+
3591
+    pdf_print_array(array, 0);
3592
+
3593
+    for (node = array->nodes; node != NULL; node = node->next)
3594
+        if (node->datasz)
3595
+            if (((char *)(node->data))[0] == 'R')
3596
+                npages++;
3593 3597
 
3594 3598
     begin = cli_memstr(obj->start + pdf->map, objsz, "/Count", 6);
3595 3599
     if (!(begin)) {
... ...
@@ -43,6 +43,7 @@ struct pdf_array_node {
43 43
 
44 44
 struct pdf_array {
45 45
     struct pdf_array_node *nodes;
46
+    struct pdf_array_node *tail;
46 47
 };
47 48
 
48 49
 #define OBJ_FLAG_PDFNAME_NONE 0x0