fmap fix reading of the last page, ole2 port to fmap

0.96
aCaB 16 years ago
parent 747c2055e4
commit c2cca657d7
  1. 8
      libclamav/fmap.c
  2. 4
      libclamav/ole2_extract.c

@ -48,8 +48,8 @@
*/
/* FIXME: tune this stuff */
#define UNPAGE_THRSHLD_HI 1*1024*1024
#define UNPAGE_THRSHLD_LO 4*1024*1024
#define UNPAGE_THRSHLD_LO 1*1024*1024
#define UNPAGE_THRSHLD_HI 4*1024*1024
struct F_MAP {
int fd;
@ -165,7 +165,7 @@ static void fmap_aging(struct F_MAP *m) {
if(avail * m->pgsz > UNPAGE_THRSHLD_HI ) {
/* if we've got more unpageable pages than we need, we pick the oldest */
fmap_qsel(m, freeme, 0, avail - 1);
avail = UNPAGE_THRSHLD_HI % m->pgsz;
avail = UNPAGE_THRSHLD_HI / m->pgsz;
}
for(i=0; i<avail; i++) {
char *pptr = (char *)m + i * m->pgsz + m->hdrsz;
@ -214,7 +214,7 @@ static int fmap_readpage(struct F_MAP *m, unsigned int page, int lock) {
/* page is not already paged */
pptr = (char *)m + page * m->pgsz + m->hdrsz;
if(page == m->pages - 1)
if((page == m->pages - 1) && (m->len % m->pgsz))
readsz = m->len % m->pgsz;
else
readsz = m->pgsz;

@ -913,7 +913,7 @@ int cli_ole2_extract(int fd, const char *dirname, cli_ctx *ctx, struct uniq **vb
hdr.m_length = statbuf.st_size;
hdr.map = fmap(fd, 0, hdr.m_length);
if (hdr.map) {
void *phdr = fmap_need_off(hdr.map, 0, hdr_size);
void *phdr = fmap_need_off_once(hdr.map, 0, hdr_size);
if(phdr) {
cli_dbgmsg("mmap'ed file\n");
memcpy(&hdr, phdr, hdr_size);
@ -936,7 +936,7 @@ int cli_ole2_extract(int fd, const char *dirname, cli_ctx *ctx, struct uniq **vb
}
#endif
}
hdr.minor_version = ole2_endian_convert_16(hdr.minor_version);
hdr.dll_version = ole2_endian_convert_16(hdr.dll_version);
hdr.byte_order = ole2_endian_convert_16(hdr.byte_order);

Loading…
Cancel
Save