Browse code

pdf: better object dictionary logging and handling

David Raynor authored on 2013/03/22 00:53:28
Showing 1 changed files
... ...
@@ -843,6 +843,8 @@ static int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj)
843 843
     char *decrypted = NULL;
844 844
     int dump = 1;
845 845
 
846
+    cli_dbgmsg("pdf_extract_obj: obj %u %u\n", obj->id>>8, obj->id&0xff);
847
+
846 848
     /* TODO: call bytecode hook here, allow override dumpability */
847 849
     if ((!(obj->flags & (1 << OBJ_STREAM)) ||
848 850
 	(obj->flags & (1 << OBJ_HASFILTERS)))
... ...
@@ -1076,7 +1078,10 @@ static int pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj)
1076 1076
       } while (bytesleft > 0);
1077 1077
     } else {
1078 1078
 	off_t bytesleft = obj_size(pdf, obj, 0);
1079
-	if (filter_writen(pdf, obj, fout , pdf->map + obj->start, bytesleft,&sum) != bytesleft)
1079
+	if (bytesleft < 0) {
1080
+	    rc = CL_EFORMAT;
1081
+	}
1082
+	else if (filter_writen(pdf, obj, fout , pdf->map + obj->start, bytesleft,&sum) != bytesleft)
1080 1083
 	    rc = CL_EWRITE;
1081 1084
     }
1082 1085
     } while (0);
... ...
@@ -1298,6 +1303,7 @@ static void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj)
1298 1298
 	nextobj = pdf_nextobject(q, bytesleft);
1299 1299
 	bytesleft -= nextobj -q;
1300 1300
 	if (!nextobj || bytesleft < 0) {
1301
+	    cli_dbgmsg("cli_pdf: %u %u obj: no dictionary\n", obj->id>>8, obj->id&0xff);
1301 1302
 	    return;
1302 1303
 	}
1303 1304
 	q3 = memchr(q-1, '<', nextobj-q+1);
... ...
@@ -1313,6 +1319,7 @@ static void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj)
1313 1313
 
1314 1314
     /* find end of dictionary block */
1315 1315
     if (bytesleft < 0) {
1316
+        cli_dbgmsg("cli_pdf: %u %u obj: broken dictionary\n", obj->id>>8, obj->id&0xff);
1316 1317
         return;
1317 1318
     }
1318 1319