make the code independent of external bzlib

git-svn: trunk@3060
remotes/push_mirror/metadata
Tomasz Kojm 18 years ago
parent 602e35c833
commit ae55464f3a
  1. 4
      ChangeLog
  2. 52
      libclamav/nsis/bzlib.c
  3. 36
      libclamav/nsis/bzlib_private.h
  4. 11
      libclamav/nsis/nulsft.c
  5. 4
      libclamav/scanners.c

@ -1,3 +1,7 @@
Wed May 23 15:14:44 CEST 2007 (tk)
----------------------------------
* libclamav/nsis: make the code independent of external bzlib
Mon May 21 20:48:00 EEST 2007 (edwin)
----------------------------------
* libclamav/nsis/nsis_zlib.h: use _NSIS_ZLIB_H instead of _ZLIB_H

@ -30,8 +30,6 @@
#include "clamav-config.h"
#endif
#ifdef HAVE_BZLIB_H
#include "bzlib_private.h"
#include "others.h"
@ -169,6 +167,20 @@ void makeMaps_d ( DState* s )
lval = gPerm[zvec - gBase[zn]]; \
}
/*---------------------------------------------------*/
inline static Int32 indexIntoF ( Int32 indx, Int32 *cftab )
{
Int32 nb, na, mid;
nb = 0;
na = 256;
do {
mid = (nb + na) >> 1;
if (indx >= cftab[mid]) nb = mid; else na = mid;
}
while (na - nb != 1);
return nb;
}
/*---------------------------------------------------*/
/* Return True iff data corruption is discovered.
@ -430,7 +442,39 @@ Bool unRLE_obuf_to_output_SMALL ( DState* s )
}
}
/*---------------------------------------------------*/
static void CreateDecodeTables ( Int32 *limit,
Int32 *base,
Int32 *perm,
UChar *length,
Int32 minLen,
Int32 maxLen,
Int32 alphaSize )
{
Int32 pp, i, j, vec;
pp = 0;
for (i = minLen; i <= maxLen; i++)
for (j = 0; j < alphaSize; j++)
if (length[j] == i) { perm[pp] = j; pp++; };
for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
vec = 0;
for (i = minLen; i <= maxLen; i++) {
vec += (base[i+1] - base[i]);
limit[i] = vec-1;
vec <<= 1;
}
for (i = minLen + 1; i <= maxLen; i++)
base[i] = ((limit[i-1] + 1) << 1) - base[i];
}
/*---------------------------------------------------*/
static Int32 BZ2_decompress ( DState* s )
@ -676,7 +720,7 @@ static Int32 BZ2_decompress ( DState* s )
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
if (s->len[t][i] < minLen) minLen = s->len[t][i];
}
BZ2_hbCreateDecodeTables (
CreateDecodeTables (
&(s->limit[t][0]),
&(s->base[t][0]),
&(s->perm[t][0]),
@ -1106,5 +1150,3 @@ int BZ_API(nsis_BZ2_bzDecompressEnd) ( nsis_bzstream *strm )
/*-------------------------------------------------------------*/
/*--- end bzlib.c ---*/
/*-------------------------------------------------------------*/
#endif /* HAVE_BZLIB_H */

@ -20,6 +20,10 @@
#ifndef _BZLIB_PRIVATE_H
#define _BZLIB_PRIVATE_H
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <stdlib.h>
#ifndef BZ_NO_STDIO
@ -262,26 +266,6 @@ typedef
EState;
/*-- externs for compression. --*/
/* aCaB
extern void
BZ2_blockSort ( EState* );
extern void
BZ2_compressBlock ( EState*, Bool );
extern void
BZ2_bsInitWrite ( EState* );
extern void
BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
extern void
BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
*/
/*-- states for decompression. --*/
#define BZ_X_IDLE 1
@ -465,19 +449,9 @@ typedef
(((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
#define BZ_GET_SMALL(cccc) \
cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \
cccc = indexIntoF ( s->tPos, s->cftab ); \
s->tPos = GET_LL(s->tPos);
/*-- externs for decompression. --*/
extern Int32 BZ2_indexIntoF ( Int32, Int32* );
/* extern Int32 */
/* BZ2_decompress ( DState* ); */
extern void BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*, Int32, Int32, Int32 );
#endif

@ -32,9 +32,7 @@
#include "nulsft.h"
#include "others.h"
#include "cltypes.h"
#ifdef HAVE_BZLIB_H
#include "nsis_bzlib.h"
#endif
#include "LZMADecode.h"
#include "nsis_zlib.h"
@ -59,15 +57,10 @@ enum {
static int nsis_init(struct nsis_st *n) {
switch(n->comp) {
case COMP_BZIP2:
#ifdef HAVE_BZLIB_H
if (nsis_BZ2_bzDecompressInit(&n->bz, 0, 0)!=BZ_OK)
return CL_EBZIP;
n->freecomp=1;
break;
#else
cli_warnmsg("NSIS: Bzip2 support not compiled in\n");
return CL_ESUPPORT;
#endif
case COMP_LZMA:
lzmaInit(&n->lz);
n->freecomp=1;
@ -85,9 +78,7 @@ static void nsis_shutdown(struct nsis_st *n) {
switch(n->comp) {
case COMP_BZIP2:
#ifdef HAVE_BZLIB_H
nsis_BZ2_bzDecompressEnd(&n->bz);
#endif
break;
case COMP_LZMA:
lzmaShutdown(&n->lz);
@ -102,7 +93,6 @@ static int nsis_decomp(struct nsis_st *n) {
int ret = CL_EFORMAT;
switch(n->comp) {
case COMP_BZIP2:
#ifdef HAVE_BZLIB_H
n->bz.avail_in = n->nsis.avail_in;
n->bz.next_in = n->nsis.next_in;
n->bz.avail_out = n->nsis.avail_out;
@ -118,7 +108,6 @@ static int nsis_decomp(struct nsis_st *n) {
n->nsis.next_in = n->bz.next_in;
n->nsis.avail_out = n->bz.avail_out;
n->nsis.next_out = n->bz.next_out;
#endif /* HAVE_BZLIB_H */
break;
case COMP_LZMA:
n->lz.avail_in = n->nsis.avail_in;

@ -842,10 +842,6 @@ static int cli_scannulsft(int desc, cli_ctx *ctx, off_t offset) {
ret = nsist.solid ? CL_BREAK : CL_SUCCESS;
}
}
if(ret == CL_ESUPPORT) /* bzip2 code not compiled in, continue */
ret = CL_SUCCESS;
} else {
cli_dbgmsg("NSIS: Successully extracted file #%u\n", nsist.fno);
lseek(nsist.ofd, 0, SEEK_SET);

Loading…
Cancel
Save