From 6b7c7dc61353c6e50246f0a751fa1ffaabfbdf97 Mon Sep 17 00:00:00 2001 From: David Raynor Date: Fri, 14 Sep 2012 11:42:16 -0400 Subject: [PATCH] bb#5805: filetypes companion to bb#5750 --- libclamav/filetypes.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libclamav/filetypes.c b/libclamav/filetypes.c index 73db24dbb..8e7dc09c9 100644 --- a/libclamav/filetypes.c +++ b/libclamav/filetypes.c @@ -38,6 +38,7 @@ #include "str.h" #include "textdet.h" #include "default.h" +#include "iowrap.h" #include "htmlnorm.h" #include "entconv.h" @@ -159,6 +160,7 @@ int is_tar(const unsigned char *buf, unsigned int nbytes); cli_file_t cli_filetype2(fmap_t *map, const struct cl_engine *engine) { + unsigned char buffer[MAGIC_BUFFER_SIZE]; const unsigned char *buff; unsigned char *decoded; int bread = MIN(map->len, MAGIC_BUFFER_SIZE), sret; @@ -173,9 +175,16 @@ cli_file_t cli_filetype2(fmap_t *map, const struct cl_engine *engine) } buff = fmap_need_off_once(map, 0, bread); - if(!buff) - return CL_TYPE_ERROR; - + if(buff) { + sret = cli_memcpy(buffer, buff, bread); + if(sret) { + cli_errmsg("cli_filetype2: fileread error!\n"); + return CL_TYPE_ERROR; + } + sret = 0; + } else { + return CL_TYPE_ERROR; + } ret = cli_filetype(buff, bread, engine); if(ret == CL_TYPE_BINARY_DATA) {