Browse code

improve error detection in zip code

git-svn: trunk@1492

Tomasz Kojm authored on 2005/04/27 02:01:54
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Apr 26 18:59:16 CEST 2005 (tk)
2
+----------------------------------
3
+  * libclamav/scanners.c: improve error detection in zip code
4
+
1 5
 Thu Apr 21 12:12:29 BST 2005 (njh)
2 6
 ----------------------------------
3 7
   * libclamav:		Removed the support for non fast-tracked uuencoded
... ...
@@ -270,6 +270,7 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const
270 270
 	FILE *tmp = NULL;
271 271
 	char *buff;
272 272
 	int fd, bytes, ret = CL_CLEAN;
273
+	unsigned long int size = 0;
273 274
 	unsigned int files = 0, encrypted;
274 275
 	struct stat source;
275 276
 	struct cli_meta_node *mdata;
... ...
@@ -434,7 +435,9 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const
434 434
 	    break;
435 435
 	}
436 436
 
437
+	size = 0;
437 438
 	while((bytes = zzip_file_read(zfp, buff, FILEBUFF)) > 0) {
439
+	    size += bytes;
438 440
 	    if(fwrite(buff, 1, bytes, tmp) != (size_t) bytes) {
439 441
 		cli_dbgmsg("Zip: Can't write to file.\n");
440 442
 		zzip_file_close(zfp);
... ...
@@ -447,6 +450,12 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const
447 447
 
448 448
 	zzip_file_close(zfp);
449 449
 
450
+	if(size != zdirent.st_size) {
451
+	    cli_dbgmsg("Zip: Incorrectly decompressed (%d != %d)\n", size, zdirent.st_size);
452
+	    ret = CL_EIO;
453
+	    break;
454
+	}
455
+
450 456
 	if(fflush(tmp) != 0) {
451 457
 	    cli_dbgmsg("Zip: fflush() failed: %s\n", strerror(errno));
452 458
 	    ret = CL_EFSYNC;