bb #6478: better return code for truncated ARJ

0.98.2
David Raynor 13 years ago
parent 55a321ea3c
commit 05fa206e1c
  1. 4
      libclamav/scanners.c
  2. 18
      libclamav/unarj.c

@ -378,6 +378,7 @@ static int cli_scanarj(cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_check)
metadata.filename = NULL;
ret = cli_unarj_prepare_file(dir, &metadata);
if (ret != CL_SUCCESS) {
cli_dbgmsg("ARJ: cli_unarj_prepare_file Error: %s\n", cl_strerror(ret));
break;
}
file++;
@ -391,6 +392,9 @@ static int cli_scanarj(cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_check)
continue;
}
ret = cli_unarj_extract_file(dir, &metadata);
if (ret != CL_SUCCESS) {
cli_dbgmsg("ARJ: cli_unarj_extract_file Error: %s\n", cl_strerror(ret));
}
if (metadata.ofd >= 0) {
lseek(metadata.ofd, 0, SEEK_SET);
rc = cli_magic_scandesc(metadata.ofd, ctx);

@ -761,7 +761,7 @@ static int decode_f(arj_metadata_t *metadata)
return CL_SUCCESS;
}
static uint32_t arj_unstore(arj_metadata_t *metadata, int ofd, uint32_t len)
static int arj_unstore(arj_metadata_t *metadata, int ofd, uint32_t len)
{
const unsigned char *data;
uint32_t rem;
@ -774,15 +774,18 @@ static uint32_t arj_unstore(arj_metadata_t *metadata, int ofd, uint32_t len)
while (rem > 0) {
todo = (unsigned int) MIN(8192, rem);
data = fmap_need_off_once_len(metadata->map, metadata->offset, todo, &count);
if (!data || !count)
return len - rem;
if (!data || !count) {
/* Truncated file, not enough bytes available */
return CL_EFORMAT;
}
metadata->offset += count;
if (cli_writen(ofd, data, count) != count) {
return len-rem-count;
/* File writing problem */
return CL_EWRITE;
}
rem -= count;
}
return len;
return CL_SUCCESS;
}
static int is_arj_archive(arj_metadata_t *metadata)
@ -1028,11 +1031,6 @@ int cli_unarj_extract_file(const char *dirname, arj_metadata_t *metadata)
switch (metadata->method) {
case 0:
ret = arj_unstore(metadata, metadata->ofd, metadata->comp_size);
if (ret != metadata->comp_size) {
ret = CL_EWRITE;
} else {
ret = CL_SUCCESS;
}
break;
case 1:
case 2:

Loading…
Cancel
Save