From 19191417688dea99ba3757c3194bf911059c3135 Mon Sep 17 00:00:00 2001 From: "Micah Snyder (micasnyd)" Date: Mon, 17 May 2021 17:22:22 -0700 Subject: [PATCH] Fix ENGINE_OPTIONS_FORCE_TO_DISK scan performance There is a scan logic issue where the main libclamav scanning functions create an extra "nested" fmap for each file being scanned. This is slightly inefficient for a normal scan, but causes a major performance issue when using ENGINE_OPTIONS_FORCE_TO_DISK. It causes every scanned file to be duplicated in the temp directory before the scan. We fix this by using `cli_magic_scan()` in `scan_common()` instead of `cli_magic_scan_nested_fmap_type()`. We can do this now that the `cl_scandesc_callback()` API creates an fmap for the caller, instead of the old logic where `scan_common()` called different API's depending on whether or not we have an fmap or a file descriptor. --- libclamav/scanners.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libclamav/scanners.c b/libclamav/scanners.c index 811ed6a073..e5a89f0f5e 100644 --- a/libclamav/scanners.c +++ b/libclamav/scanners.c @@ -4874,7 +4874,7 @@ static cl_error_t scan_common(cl_fmap_t *map, const char *filepath, const char * cli_logg_setup(&ctx); - rc = cli_magic_scan_nested_fmap_type(map, 0, map->len, &ctx, CL_TYPE_ANY, target_basename); + rc = cli_magic_scan(&ctx, CL_TYPE_ANY); if (rc == CL_CLEAN && ctx.found_possibly_unwanted) { cli_virus_found_cb(&ctx);