Browse code

Bug 459

git-svn: trunk@3021

Nigel Horne authored on 2007/04/16 20:52:03
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Apr 16 11:58:30 BST 2007 (njh)
2
+----------------------------------
3
+  * libclamav/pdf.c:	Bug 459
4
+
1 5
 Sun Apr 15 21:16:08 CEST 2007 (tk)
2 6
 ----------------------------------
3 7
   * libclamav/chmunpack.c: fix fd leak in chm_decompress_stream (CVE-2007-1745)
... ...
@@ -291,16 +291,21 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx)
291 291
 					 */
292 292
 					if((bytesleft > 11) && strncmp(q, " 0 R", 4) == 0) {
293 293
 						const char *r;
294
-						char b[13];
294
+						char b[14];
295 295
 
296 296
 						q += 4;
297 297
 						cli_dbgmsg("Length is in indirect obj %d\n",
298 298
 							length);
299 299
 						snprintf(b, sizeof(b),
300
-							"%d 0 obj", length);
300
+							"\n%d 0 obj", length);
301 301
 						length = strlen(b);
302 302
 						r = cli_pmemstr(alloced ? alloced : buf,
303 303
 							size, b, length);
304
+						if(r == NULL) {
305
+							b[0] = '\r';
306
+							r = cli_pmemstr(alloced ? alloced : buf,
307
+								size, b, length);
308
+						}
304 309
 						if(r) {
305 310
 							r += length - 1;
306 311
 							r = pdf_nextobject(r, bytesleft - (r - q));
... ...
@@ -309,11 +314,12 @@ cli_pdf(const char *dir, int desc, const cli_ctx *ctx)
309 309
 								while(isdigit(*r))
310 310
 									r++;
311 311
 								cli_dbgmsg("length in '%s' %d\n",
312
-									b, length);
312
+									&b[1],
313
+									length);
313 314
 							}
314 315
 						} else
315 316
 							cli_warnmsg("Couldn't find '%s'\n",
316
-								b);
317
+								&b[1]);
317 318
 					}
318 319
 					q--;
319 320
 				} else if(strncmp(q, "Length2 ", 8) == 0)
... ...
@@ -551,6 +557,11 @@ flatedecode(unsigned char *buf, off_t len, int fout, const cli_ctx *ctx)
551 551
 
552 552
 	cli_dbgmsg("cli_pdf: flatedecode %lu bytes\n", (unsigned long)len);
553 553
 
554
+	if(len == 0) {
555
+		cli_warnmsg("cli_pdf: flatedecode len == 0\n");
556
+		return Z_OK;
557
+	}
558
+
554 559
 #ifdef	SAVE_TMP
555 560
 	/*
556 561
 	 * Copy the embedded area for debugging, so that if it falls over