Browse code

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.

Micah Snyder (micasnyd) authored on 2021/05/18 09:22:22
Showing 1 changed files
... ...
@@ -4875,7 +4875,7 @@ static cl_error_t scan_common(cl_fmap_t *map, const char *filepath, const char *
4875 4875
 
4876 4876
     cli_logg_setup(&ctx);
4877 4877
 
4878
-    rc = cli_magic_scan_nested_fmap_type(map, 0, map->len, &ctx, CL_TYPE_ANY, target_basename);
4878
+    rc = cli_magic_scan(&ctx, CL_TYPE_ANY);
4879 4879
 
4880 4880
     if (rc == CL_CLEAN && ctx.found_possibly_unwanted) {
4881 4881
         cli_virus_found_cb(&ctx);