Browse code

Fix for 3 pdf parsing bugs introduced with the addition of object stream parsing, identified in regression testing.

Micah Snyder (micasnyd) authored on 2018/10/26 05:06:15
Showing 1 changed files
... ...
@@ -1737,8 +1737,15 @@ int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t flags)
1737 1737
 
1738 1738
             if (bytesleft < 0)
1739 1739
                 rc = CL_EFORMAT;
1740
-            else if (filter_writen(pdf, obj, fout , pdf->map + obj->start, bytesleft, (size_t*)&sum) != (size_t)bytesleft)
1741
-                rc = CL_EWRITE;
1740
+            else {
1741
+                if (obj->objstm) {
1742
+                    if (filter_writen(pdf, obj, fout , obj->objstm->streambuf + obj->start, bytesleft, (size_t*)&sum) != (size_t)bytesleft)
1743
+                        rc = CL_EWRITE;
1744
+                } else {
1745
+                    if (filter_writen(pdf, obj, fout , pdf->map + obj->start, bytesleft, (size_t*)&sum) != (size_t)bytesleft)
1746
+                        rc = CL_EWRITE;
1747
+                }
1748
+            }
1742 1749
         }
1743 1750
     } while (0);
1744 1751
 
... ...
@@ -2842,7 +2849,8 @@ void pdf_handle_enc(struct pdf_struct *pdf)
2842 2842
     }
2843 2843
 
2844 2844
     len = obj_size(pdf, obj, 1);
2845
-    q = pdf->map + obj->start;
2845
+    q = (obj->objstm) ? (const char *)(obj->start + obj->objstm->streambuf)
2846
+                      : (const char *)(obj->start + pdf->map);
2846 2847
 
2847 2848
     O = U = UE = StmF = StrF = EFF = NULL;
2848 2849
     do {
... ...
@@ -4105,6 +4113,7 @@ static void Pages_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname
4105 4105
     unsigned long npages=0, count;
4106 4106
     struct pdf_array_node *node;
4107 4107
     json_object *pdfobj;
4108
+    size_t countsize = 0;
4108 4109
 
4109 4110
     UNUSEDPARAM(act);
4110 4111
 
... ...
@@ -4151,7 +4160,10 @@ static void Pages_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname
4151 4151
         goto cleanup;
4152 4152
     }
4153 4153
 
4154
-    if ((CL_SUCCESS != cli_strntoul_wrap(begin, (size_t)(obj->start + pdf->map + objsize - begin), 0, 10, &count)) ||
4154
+    countsize = (obj->objstm) ? (size_t)(obj->start + obj->objstm->streambuf + objsize - begin)
4155
+                              : (size_t)(obj->start + pdf->map + objsize - begin);
4156
+
4157
+    if ((CL_SUCCESS != cli_strntoul_wrap(begin, countsize, 0, 10, &count)) ||
4155 4158
         (count != npages)) {
4156 4159
         cli_jsonbool(pdfobj, "IncorrectPagesCount", 1);
4157 4160
     }