[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
Tomasz Kojm
tkojm at clamav.net
Sun Apr 4 01:03:38 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 6d3c5bec1d2d4cd0211e7f6e2701750ad39e4339
Author: Tomasz Kojm <tkojm at clamav.net>
Date: Tue Sep 1 20:52:13 2009 +0200
libclamav: use BM matcher in offset mode for PE files larger than 256kB
(10% speedup on average; 30-40% for large executables)
diff --git a/ChangeLog b/ChangeLog
index 3b4141b..4b19fa8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Sep 1 20:50:12 CEST 2009 (tk)
+----------------------------------
+ * libclamav: use BM matcher in offset mode for PE files larger than 256kB
+ (10% speedup on average; 30-40% for large executables)
+
Tue Sep 1 11:11:43 CEST 2009 (tk)
----------------------------------
* libclamav: in bm_offmode only load sigs with non-floating absolute and
diff --git a/libclamav/default.h b/libclamav/default.h
index 8641fe9..c1738c5 100644
--- a/libclamav/default.h
+++ b/libclamav/default.h
@@ -28,6 +28,8 @@
#define CLI_DEFAULT_LSIG_BUFSIZE 32768
#define CLI_DEFAULT_DBIO_BUFSIZE CLI_DEFAULT_LSIG_BUFSIZE + 1
+#define CLI_DEFAULT_BM_OFFMODE_FSIZE 262144
+
#define CLI_DEFAULT_MAXSCANSIZE 104857600
#define CLI_DEFAULT_MAXFILESIZE 26214400
#define CLI_DEFAULT_MAXRECLEVEL 16
diff --git a/libclamav/matcher-bm.c b/libclamav/matcher-bm.c
index 49b248f..aa876fe 100644
--- a/libclamav/matcher-bm.c
+++ b/libclamav/matcher-bm.c
@@ -369,7 +369,7 @@ int cli_bm_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
shift = 1;
}
- if(root->bm_offmode) {
+ if(offdata) {
off = offset + i - BM_MIN_LENGTH + BM_BLOCK_SIZE;
for(; off >= offdata->offtab[offdata->pos] && offdata->pos < offdata->cnt; offdata->pos++);
if(offdata->pos == offdata->cnt || off >= offdata->offtab[offdata->pos])
diff --git a/libclamav/matcher.c b/libclamav/matcher.c
index 0e4cc04..9573f8f 100644
--- a/libclamav/matcher.c
+++ b/libclamav/matcher.c
@@ -322,7 +322,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
{
unsigned char *buffer, *buff, *endbl, *upt;
int ret = CL_CLEAN, type = CL_CLEAN, bytes;
- unsigned int i, evalcnt;
+ unsigned int i, evalcnt, bm_offmode = 0;
uint32_t buffersize, length, maxpatlen, shift = 0, offset = 0;
uint64_t evalids;
struct cli_ac_data gdata, tdata;
@@ -330,6 +330,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
cli_md5_ctx md5ctx;
unsigned char digest[16];
struct cli_matcher *groot = NULL, *troot = NULL;
+ struct stat sb;
if(!ctx->engine) {
@@ -378,11 +379,18 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
cli_ac_freedata(&gdata);
return ret;
}
- if(troot->bm_offmode && (ret = cli_bm_initoff(troot, &toff, desc))) {
- if(!ftonly)
- cli_ac_freedata(&gdata);
- cli_ac_freedata(&tdata);
- return ret;
+ if(troot->bm_offmode) {
+ if(fstat(desc, &sb) != -1) {
+ if(sb.st_size >= CLI_DEFAULT_BM_OFFMODE_FSIZE) {
+ if((ret = cli_bm_initoff(troot, &toff, desc))) {
+ if(!ftonly)
+ cli_ac_freedata(&gdata);
+ cli_ac_freedata(&tdata);
+ return ret;
+ }
+ bm_offmode = 1;
+ }
+ }
}
}
@@ -406,7 +414,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
length += maxpatlen;
if(troot) {
- if(troot->ac_only || (ret = cli_bm_scanbuff(upt, length, ctx->virname, troot, offset, desc, &toff)) != CL_VIRUS)
+ if(troot->ac_only || (ret = cli_bm_scanbuff(upt, length, ctx->virname, troot, offset, desc, bm_offmode ? &toff : NULL)) != CL_VIRUS)
ret = cli_ac_scanbuff(upt, length, ctx->virname, NULL, NULL, troot, &tdata, offset, ftype, ftoffset, acmode, NULL);
if(ret == CL_VIRUS) {
@@ -414,7 +422,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
if(!ftonly)
cli_ac_freedata(&gdata);
cli_ac_freedata(&tdata);
- if(troot->bm_offmode)
+ if(bm_offmode)
cli_bm_freeoff(&toff);
if(cli_checkfp(desc, ctx))
@@ -433,7 +441,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
cli_ac_freedata(&gdata);
if(troot) {
cli_ac_freedata(&tdata);
- if(troot->bm_offmode)
+ if(bm_offmode)
cli_bm_freeoff(&toff);
}
if(cli_checkfp(desc, ctx))
@@ -480,7 +488,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
}
}
cli_ac_freedata(&tdata);
- if(troot->bm_offmode)
+ if(bm_offmode)
cli_bm_freeoff(&toff);
}
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list