Browse code

bb #6804 and pdf_parse_trailer()

David Raynor authored on 2013/02/13 05:16:18
Showing 1 changed files
... ...
@@ -876,6 +876,17 @@ static void handle_pdfname(struct pdf_struct *pdf, struct pdf_obj *obj,
876 876
 static char *pdf_readstring(const char *q0, int len, const char *key, unsigned *slen);
877 877
 static int pdf_readint(const char *q0, int len, const char *key);
878 878
 static const char *pdf_getdict(const char *q0, int* len, const char *key);
879
+
880
+static void pdf_parse_trailer(struct pdf_struct *pdf, const char *s, long length)
881
+{
882
+    char *newID;
883
+    newID = pdf_readstring(s, length, "/ID", &pdf->fileIDlen);
884
+    if (newID) {
885
+        free(pdf->fileID);
886
+        pdf->fileID = newID;
887
+    }
888
+}
889
+
879 890
 static void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj)
880 891
 {
881 892
     /* enough to hold common pdf names, we don't need all the names */
... ...
@@ -960,9 +971,9 @@ static void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj)
960 960
 		if (trailer < 0) trailer = 0;
961 961
 		q2 = pdf->map + trailer;
962 962
 		cli_dbgmsg("cli_pdf: looking for trailer in linearized pdf: %ld - %ld\n", trailer, trailer_end);
963
-		pdf->fileID = pdf_readstring(q2, trailer_end - trailer, "/ID", &pdf->fileIDlen);
963
+		pdf_parse_trailer(pdf, q2, trailer_end - trailer);
964 964
 		if (pdf->fileID)
965
-		    cli_dbgmsg("found fileID\n");
965
+		    cli_dbgmsg("cli_pdf: found fileID\n");
966 966
 	    }
967 967
 	}
968 968
 	if (objstate == STATE_LAUNCHACTION)
... ...
@@ -1281,7 +1292,7 @@ static void check_user_password(struct pdf_struct *pdf, int R, const char *O,
1281 1281
 	if (!pdf->key)
1282 1282
 	    return;
1283 1283
 	memcpy(pdf->key, result, pdf->keylen);
1284
-	dbg_printhex("md5", result, 32);
1284
+	dbg_printhex("md5", result, 16);
1285 1285
 	dbg_printhex("Candidate encryption key", pdf->key, pdf->keylen);
1286 1286
 
1287 1287
 	/* 7.6.3.3 Algorithm 6 */
... ...
@@ -1521,7 +1532,7 @@ int cli_pdf(const char *dir, cli_ctx *ctx, off_t offset)
1521 1521
 		pdf.flags |= 1 << ENCRYPTED_PDF;
1522 1522
 		cli_dbgmsg("cli_pdf: encrypted pdf found, stream will probably fail to decompress!\n");
1523 1523
 		pdf_parse_encrypt(&pdf, enc, eof - enc);
1524
-		pdf.fileID = pdf_readstring(eofmap, bytesleft, "/ID", &pdf.fileIDlen);
1524
+		pdf_parse_trailer(&pdf, eofmap, bytesleft);
1525 1525
 	    }
1526 1526
 	    q += 9;
1527 1527
 	    while (q < eof && (*q == ' ' || *q == '\n' || *q == '\r')) { q++; }
... ...
@@ -1553,7 +1564,7 @@ int cli_pdf(const char *dir, cli_ctx *ctx, off_t offset)
1553 1553
     /* parse PDF and find obj offsets */
1554 1554
     while ((rc = pdf_findobj(&pdf)) > 0) {
1555 1555
 	struct pdf_obj *obj = &pdf.objs[pdf.nobjs-1];
1556
-	cli_dbgmsg("found %d %d obj @%ld\n", obj->id >> 8, obj->id&0xff, obj->start + offset);
1556
+	cli_dbgmsg("cli_pdf: found %d %d obj @%ld\n", obj->id >> 8, obj->id&0xff, obj->start + offset);
1557 1557
     }
1558 1558
     if (pdf.nobjs)
1559 1559
 	pdf.nobjs--;
... ...
@@ -2276,7 +2287,7 @@ ascii85decode(const char *buf, off_t len, unsigned char *output)
2276 2276
 			}
2277 2277
 		} else if(byte == 'z') {
2278 2278
 			if(quintet) {
2279
-				cli_dbgmsg("ascii85decode: unexpected 'z'\n");
2279
+				cli_dbgmsg("cli_pdf: ascii85decode: unexpected 'z'\n");
2280 2280
 				return -1;
2281 2281
 			}
2282 2282
 			*output++ = '\0';
... ...
@@ -2285,12 +2296,12 @@ ascii85decode(const char *buf, off_t len, unsigned char *output)
2285 2285
 			*output++ = '\0';
2286 2286
 			ret += 4;
2287 2287
 		} else if(byte == EOF) {
2288
-			cli_dbgmsg("ascii85decode: quintet %d\n", quintet);
2288
+			cli_dbgmsg("cli_pdf: ascii85decode: quintet %d\n", quintet);
2289 2289
 			if(quintet) {
2290 2290
 				int i;
2291 2291
 
2292 2292
 				if(quintet == 1) {
2293
-					cli_dbgmsg("ascii85Decode: only 1 byte in last quintet\n");
2293
+					cli_dbgmsg("cli_pdf: ascii85Decode: only 1 byte in last quintet\n");
2294 2294
 					return -1;
2295 2295
 				}
2296 2296
 				for(i = quintet; i < 5; i++)
... ...
@@ -2304,7 +2315,7 @@ ascii85decode(const char *buf, off_t len, unsigned char *output)
2304 2304
 			}
2305 2305
 			break;
2306 2306
 		} else if(!isspace(byte)) {
2307
-			cli_dbgmsg("ascii85Decode: invalid character 0x%x, len %lu\n",
2307
+			cli_dbgmsg("cli_pdf: ascii85Decode: invalid character 0x%x, len %lu\n",
2308 2308
 				byte & 0xFF, (unsigned long)len);
2309 2309
 			return -1;
2310 2310
 		}