aboutsummaryrefslogtreecommitdiff
path: root/src/main/extractor_datasource.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/extractor_datasource.c')
-rw-r--r--src/main/extractor_datasource.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/main/extractor_datasource.c b/src/main/extractor_datasource.c
index 4efe3b2..e2f151a 100644
--- a/src/main/extractor_datasource.c
+++ b/src/main/extractor_datasource.c
@@ -364,7 +364,10 @@ bfds_seek (struct BufferedFileDataSource *bfds,
364 } 364 }
365 if (pos > bfds->fsize) 365 if (pos > bfds->fsize)
366 { 366 {
367 LOG ("Invalid seek operation\n"); 367 LOG ("Invalid seek operation (%lld > %llu) %d\n",
368 (long long) pos,
369 (unsigned long long) bfds->fsize,
370 SEEK_SET == whence);
368 return -1; 371 return -1;
369 } 372 }
370 if ( (NULL == bfds->buffer) || 373 if ( (NULL == bfds->buffer) ||
@@ -538,8 +541,7 @@ cfs_init_decompressor_zlib (struct CompressedFileSource *cfs,
538 if (sizeof (hdata) > bfds_read (cfs->bfds, hdata, sizeof (hdata))) 541 if (sizeof (hdata) > bfds_read (cfs->bfds, hdata, sizeof (hdata)))
539 return -1; 542 return -1;
540 if (0 != (hdata[3] & 0x4)) /* FEXTRA set */ 543 if (0 != (hdata[3] & 0x4)) /* FEXTRA set */
541 gzip_header_length += 2 + (unsigned) (hdata[10] & 0xff) + 544 gzip_header_length += 2 + (hdata[10] & 0xff) + ((hdata[11] & 0xff) * 256);
542 (((unsigned) (hdata[11] & 0xff)) * 256);
543 545
544 if (0 != (hdata[3] & 0x8)) 546 if (0 != (hdata[3] & 0x8))
545 { 547 {
@@ -550,18 +552,27 @@ cfs_init_decompressor_zlib (struct CompressedFileSource *cfs,
550 ssize_t buf_bytes; 552 ssize_t buf_bytes;
551 553
552 if (gzip_header_length > bfds_seek (cfs->bfds, gzip_header_length, SEEK_SET)) 554 if (gzip_header_length > bfds_seek (cfs->bfds, gzip_header_length, SEEK_SET))
553 return -1; 555 {
556 LOG ("Corrupt gzip, failed to seek to end of header\n");
557 return -1;
558 }
554 buf_bytes = bfds_read (cfs->bfds, fname, sizeof (fname)); 559 buf_bytes = bfds_read (cfs->bfds, fname, sizeof (fname));
555 if (buf_bytes <= 0) 560 if (buf_bytes <= 0)
556 return -1; 561 {
562 LOG ("Corrupt gzip, failed to read filename\n");
563 return -1;
564 }
557 if (NULL == (cptr = memchr (fname, 0, buf_bytes))) 565 if (NULL == (cptr = memchr (fname, 0, buf_bytes)))
558 return -1; 566 {
567 LOG ("Corrupt gzip, failed to read filename terminator\n");
568 return -1;
569 }
559 len = cptr - fname; 570 len = cptr - fname;
560 if (0 != proc (proc_cls, "<zlib>", EXTRACTOR_METATYPE_FILENAME, 571 if (0 != proc (proc_cls, "<zlib>", EXTRACTOR_METATYPE_FILENAME,
561 EXTRACTOR_METAFORMAT_C_STRING, "text/plain", 572 EXTRACTOR_METAFORMAT_C_STRING, "text/plain",
562 fname, 573 fname,
563 len)) 574 len))
564 return 0; /* done */ 575 return 0; /* done */
565 gzip_header_length += len + 1; 576 gzip_header_length += len + 1;
566 } 577 }
567 578
@@ -574,12 +585,21 @@ cfs_init_decompressor_zlib (struct CompressedFileSource *cfs,
574 size_t len; 585 size_t len;
575 586
576 if (gzip_header_length > bfds_seek (cfs->bfds, gzip_header_length, SEEK_SET)) 587 if (gzip_header_length > bfds_seek (cfs->bfds, gzip_header_length, SEEK_SET))
577 return -1; 588 {
589 LOG ("Corrupt gzip, failed to seek to end of header\n");
590 return -1;
591 }
578 buf_bytes = bfds_read (cfs->bfds, fcomment, sizeof (fcomment)); 592 buf_bytes = bfds_read (cfs->bfds, fcomment, sizeof (fcomment));
579 if (buf_bytes <= 0) 593 if (buf_bytes <= 0)
580 return -1; 594 {
595 LOG ("Corrupt gzip, failed to read comment\n");
596 return -1;
597 }
581 if (NULL == (cptr = memchr (fcomment, 0, buf_bytes))) 598 if (NULL == (cptr = memchr (fcomment, 0, buf_bytes)))
582 return -1; 599 {
600 LOG ("Corrupt gzip, failed to read comment terminator\n");
601 return -1;
602 }
583 len = cptr - fcomment; 603 len = cptr - fcomment;
584 if (0 != proc (proc_cls, "<zlib>", EXTRACTOR_METATYPE_COMMENT, 604 if (0 != proc (proc_cls, "<zlib>", EXTRACTOR_METATYPE_COMMENT,
585 EXTRACTOR_METAFORMAT_C_STRING, "text/plain", 605 EXTRACTOR_METAFORMAT_C_STRING, "text/plain",