git-svn: trunk@2554
Nigel Horne authored on 2006/12/13 22:52:39... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Wed Dec 13 13:51:32 GMT 2006 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/blob.c: Fix a performance issue raised by Steve Basford, |
|
4 |
+ steveb*newburydata.co.uk |
|
5 |
+ |
|
1 | 6 |
Tue Dec 12 14:57:11 CET 2006 (tk) |
2 | 7 |
--------------------------------- |
3 | 8 |
* libclamav: add separate limit value for mail recursion level |
... | ... |
@@ -16,7 +16,7 @@ |
16 | 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
17 | 17 |
* MA 02110-1301, USA. |
18 | 18 |
*/ |
19 |
-static char const rcsid[] = "$Id: blob.c,v 1.58 2006/12/11 11:51:14 njh Exp $"; |
|
19 |
+static char const rcsid[] = "$Id: blob.c,v 1.59 2006/12/13 13:50:51 njh Exp $"; |
|
20 | 20 |
|
21 | 21 |
#if HAVE_CONFIG_H |
22 | 22 |
#include "clamav-config.h" |
... | ... |
@@ -63,6 +63,12 @@ static char const rcsid[] = "$Id: blob.c,v 1.58 2006/12/11 11:51:14 njh Exp $"; |
63 | 63 |
#include <windows.h> |
64 | 64 |
#endif |
65 | 65 |
|
66 |
+#define MAX_SCAN_SIZE 20*1024 /* |
|
67 |
+ * The performance benefit of scanning |
|
68 |
+ * early disappears on medium and |
|
69 |
+ * large sized files |
|
70 |
+ */ |
|
71 |
+ |
|
66 | 72 |
blob * |
67 | 73 |
blobCreate(void) |
68 | 74 |
{ |
... | ... |
@@ -466,7 +472,7 @@ fileblobSetFilename(fileblob *fb, const char *dir, const char *filename) |
466 | 466 |
return; |
467 | 467 |
} |
468 | 468 |
|
469 |
- cli_dbgmsg("Saving attachment as %s\n", fullname); |
|
469 |
+ cli_dbgmsg("Creating %s\n", fullname); |
|
470 | 470 |
|
471 | 471 |
fb->fp = fdopen(fd, "wb"); |
472 | 472 |
|
... | ... |
@@ -494,17 +500,32 @@ fileblobAddData(fileblob *fb, const unsigned char *data, size_t len) |
494 | 494 |
assert(data != NULL); |
495 | 495 |
|
496 | 496 |
if(fb->fp) { |
497 |
+#if defined(MAX_SCAN_SIZE) && (MAX_SCAN_SIZE > 0) |
|
498 |
+ const cli_ctx *ctx = fb->ctx; |
|
499 |
+ |
|
497 | 500 |
if(fb->isInfected) /* pretend all was written */ |
498 | 501 |
return 0; |
499 |
- if(fb->ctx) { |
|
500 |
- if(fb->ctx->scanned) |
|
501 |
- *fb->ctx->scanned += (unsigned long)len / CL_COUNT_PRECISION; |
|
502 |
- |
|
503 |
- if((len > 5) && (cli_scanbuff(data, (unsigned int)len, fb->ctx->virname, fb->ctx->engine, 0) == CL_VIRUS)) { |
|
504 |
- cli_dbgmsg("fileblobAddData: found %s\n", *fb->ctx->virname); |
|
505 |
- fb->isInfected = 1; |
|
502 |
+ if(ctx) { |
|
503 |
+ int do_scan = 1; |
|
504 |
+ |
|
505 |
+ if(ctx->limits) |
|
506 |
+ if(fb->bytes_scanned >= ctx->limits->maxfilesize) |
|
507 |
+ do_scan = 0; |
|
508 |
+ |
|
509 |
+ if(fb->bytes_scanned > MAX_SCAN_SIZE) |
|
510 |
+ do_scan = 0; |
|
511 |
+ if(do_scan) { |
|
512 |
+ if(ctx->scanned) |
|
513 |
+ *ctx->scanned += (unsigned long)len / CL_COUNT_PRECISION; |
|
514 |
+ fb->bytes_scanned += (unsigned long)len; |
|
515 |
+ |
|
516 |
+ if((len > 5) && (cli_scanbuff(data, (unsigned int)len, ctx->virname, ctx->engine, 0) == CL_VIRUS)) { |
|
517 |
+ cli_dbgmsg("fileblobAddData: found %s\n", *ctx->virname); |
|
518 |
+ fb->isInfected = 1; |
|
519 |
+ } |
|
506 | 520 |
} |
507 | 521 |
} |
522 |
+#endif |
|
508 | 523 |
|
509 | 524 |
if(fwrite(data, len, 1, fb->fp) != 1) { |
510 | 525 |
cli_errmsg("fileblobAddData: Can't write %u bytes to temporary file %s: %s\n", len, fb->b.name, strerror(errno)); |