Browse code

pdfdecode: add error flags in asciihex and ascii85

Kevin Lin authored on 2016/04/01 04:19:07
Showing 1 changed files
... ...
@@ -74,10 +74,10 @@ struct pdf_token {
74 74
 static  int pdf_decodestream_internal(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, struct pdf_token *token);
75 75
 static  int pdf_decode_dump(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_token *token, int lvl);
76 76
 
77
-static  int filter_ascii85decode(struct pdf_token *token);
77
+static  int filter_ascii85decode(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_token *token);
78 78
 static  int filter_rldecode(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_token *token);
79 79
 static  int filter_flatedecode(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, struct pdf_token *token);
80
-static  int filter_asciihexdecode(struct pdf_token *token);
80
+static  int filter_asciihexdecode(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_token *token);
81 81
 static  int filter_decrypt(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_dict *params, struct pdf_token *token, int mode);
82 82
 
83 83
 
... ...
@@ -151,7 +151,7 @@ static int pdf_decodestream_internal(struct pdf_struct *pdf, struct pdf_obj *obj
151 151
         switch(obj->filterlist[i]) {
152 152
         case OBJ_FILTER_A85:
153 153
             cli_dbgmsg("cli_pdf: decoding [%d] => ASCII85DECODE\n", obj->filterlist[i]);
154
-            rc = filter_ascii85decode(token);
154
+            rc = filter_ascii85decode(pdf, obj, token);
155 155
             break;
156 156
 
157 157
         case OBJ_FILTER_RL:
... ...
@@ -166,7 +166,7 @@ static int pdf_decodestream_internal(struct pdf_struct *pdf, struct pdf_obj *obj
166 166
 
167 167
         case OBJ_FILTER_AH:
168 168
             cli_dbgmsg("cli_pdf: decoding [%d] => ASCIIHEXDECODE\n", obj->filterlist[i]);
169
-            rc = filter_asciihexdecode(token);
169
+            rc = filter_asciihexdecode(pdf, obj, token);
170 170
             break;
171 171
 
172 172
         case OBJ_FILTER_CRYPT:
... ...
@@ -253,7 +253,7 @@ static int pdf_decode_dump(struct pdf_struct *pdf, struct pdf_obj *obj, struct p
253 253
  * ascii85 inflation
254 254
  * See http://www.piclist.com/techref/method/encode.htm (look for base85)
255 255
  */
256
-static int filter_ascii85decode(struct pdf_token *token)
256
+static int filter_ascii85decode(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_token *token)
257 257
 {
258 258
     uint8_t *decoded;
259 259
     uint32_t declen = 0;
... ...
@@ -346,6 +346,9 @@ static int filter_ascii85decode(struct pdf_token *token)
346 346
         token->content = decoded;
347 347
         token->length = declen;
348 348
     } else {
349
+        if (!(obj->flags & ((1 << OBJ_IMAGE) | (1 << OBJ_TRUNCATED))))
350
+            pdfobj_flag(pdf, obj, BAD_ASCIIDECODE);
351
+
349 352
         cli_errmsg("cli_pdf: error occurred parsing byte %lu of %lu\n",
350 353
                    (unsigned long)(token->length-remaining), (unsigned long)(token->length));
351 354
         free(decoded);
... ...
@@ -610,7 +613,7 @@ static int filter_flatedecode(struct pdf_struct *pdf, struct pdf_obj *obj, struc
610 610
     return rc;
611 611
 }
612 612
 
613
-static int filter_asciihexdecode(struct pdf_token *token)
613
+static int filter_asciihexdecode(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf_token *token)
614 614
 {
615 615
     uint8_t *decoded;
616 616
 
... ...
@@ -652,6 +655,9 @@ static int filter_asciihexdecode(struct pdf_token *token)
652 652
         token->content = decoded;
653 653
         token->length = j;
654 654
     } else {
655
+        if (!(obj->flags & ((1 << OBJ_IMAGE) | (1 << OBJ_TRUNCATED))))
656
+            pdfobj_flag(pdf, obj, BAD_ASCIIDECODE);
657
+
655 658
         cli_errmsg("cli_pdf: error occurred parsing byte %lu of %lu\n",
656 659
                    (unsigned long)i, (unsigned long)(token->length));
657 660
         free(decoded);