mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
See ChangeLog: Wed Jan 13 14:10:15 CET 1999 Werner Koch
This commit is contained in:
parent
615e15dd68
commit
e99e43cd53
32 changed files with 2085 additions and 823 deletions
|
@ -1,5 +1,5 @@
|
|||
/* infblock.c -- interpret and process block types to last block
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -11,8 +11,12 @@
|
|||
|
||||
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
/* Table for deflate from PKZIP's appnote.txt. */
|
||||
local uInt border[] = { /* Order of the bit length code lengths */
|
||||
local const uInt border[] = { /* Order of the bit length code lengths */
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
/*
|
||||
|
@ -66,23 +70,19 @@ inflate_blocks_statef *s;
|
|||
z_streamp z;
|
||||
uLongf *c;
|
||||
{
|
||||
if (s->checkfn != Z_NULL)
|
||||
if (c != Z_NULL)
|
||||
*c = s->check;
|
||||
if (s->mode == BTREE || s->mode == DTREE)
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
if (s->mode == CODES)
|
||||
{
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
inflate_trees_free(s->sub.decode.td, z);
|
||||
inflate_trees_free(s->sub.decode.tl, z);
|
||||
}
|
||||
s->mode = TYPE;
|
||||
s->bitk = 0;
|
||||
s->bitb = 0;
|
||||
s->read = s->write = s->window;
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(0L, Z_NULL, 0);
|
||||
Trace((stderr, "inflate: blocks reset\n"));
|
||||
z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
|
||||
Tracev((stderr, "inflate: blocks reset\n"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,23 +96,27 @@ uInt w;
|
|||
if ((s = (inflate_blocks_statef *)ZALLOC
|
||||
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
|
||||
return s;
|
||||
if ((s->hufts =
|
||||
(inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, s);
|
||||
return Z_NULL;
|
||||
}
|
||||
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, s->hufts);
|
||||
ZFREE(z, s);
|
||||
return Z_NULL;
|
||||
}
|
||||
s->end = s->window + w;
|
||||
s->checkfn = c;
|
||||
s->mode = TYPE;
|
||||
Trace((stderr, "inflate: blocks allocated\n"));
|
||||
inflate_blocks_reset(s, z, &s->check);
|
||||
Tracev((stderr, "inflate: blocks allocated\n"));
|
||||
inflate_blocks_reset(s, z, Z_NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
extern uInt inflate_hufts;
|
||||
#endif
|
||||
int inflate_blocks(s, z, r)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
|
@ -139,7 +143,7 @@ int r;
|
|||
switch (t >> 1)
|
||||
{
|
||||
case 0: /* stored */
|
||||
Trace((stderr, "inflate: stored block%s\n",
|
||||
Tracev((stderr, "inflate: stored block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
DUMPBITS(3)
|
||||
t = k & 7; /* go to byte boundary */
|
||||
|
@ -147,27 +151,25 @@ int r;
|
|||
s->mode = LENS; /* get length of stored block */
|
||||
break;
|
||||
case 1: /* fixed */
|
||||
Trace((stderr, "inflate: fixed codes block%s\n",
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
{
|
||||
uInt bl, bd;
|
||||
inflate_huft *tl, *td;
|
||||
|
||||
inflate_trees_fixed(&bl, &bd, &tl, &td);
|
||||
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
|
||||
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
|
||||
if (s->sub.decode.codes == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.decode.tl = Z_NULL; /* don't try to free these */
|
||||
s->sub.decode.td = Z_NULL;
|
||||
}
|
||||
DUMPBITS(3)
|
||||
s->mode = CODES;
|
||||
break;
|
||||
case 2: /* dynamic */
|
||||
Trace((stderr, "inflate: dynamic codes block%s\n",
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
DUMPBITS(3)
|
||||
s->mode = TABLE;
|
||||
|
@ -224,8 +226,6 @@ int r;
|
|||
}
|
||||
#endif
|
||||
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
|
||||
if (t < 19)
|
||||
t = 19;
|
||||
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
|
@ -246,9 +246,10 @@ int r;
|
|||
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
|
||||
s->sub.trees.bb = 7;
|
||||
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
|
||||
&s->sub.trees.tb, z);
|
||||
&s->sub.trees.tb, s->hufts, z);
|
||||
if (t != Z_OK)
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
r = t;
|
||||
if (r == Z_DATA_ERROR)
|
||||
s->mode = BAD;
|
||||
|
@ -267,8 +268,8 @@ int r;
|
|||
t = s->sub.trees.bb;
|
||||
NEEDBITS(t)
|
||||
h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
|
||||
t = h->word.what.Bits;
|
||||
c = h->more.Base;
|
||||
t = h->bits;
|
||||
c = h->base;
|
||||
if (c < 16)
|
||||
{
|
||||
DUMPBITS(t)
|
||||
|
@ -287,6 +288,7 @@ int r;
|
|||
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
|
||||
(c == 16 && i < 1))
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"invalid bit length repeat";
|
||||
r = Z_DATA_ERROR;
|
||||
|
@ -299,7 +301,6 @@ int r;
|
|||
s->sub.trees.index = i;
|
||||
}
|
||||
}
|
||||
inflate_trees_free(s->sub.trees.tb, z);
|
||||
s->sub.trees.tb = Z_NULL;
|
||||
{
|
||||
uInt bl, bd;
|
||||
|
@ -309,11 +310,10 @@ int r;
|
|||
bl = 9; /* must be <= 9 for lookahead assumptions */
|
||||
bd = 6; /* must be <= 9 for lookahead assumptions */
|
||||
t = s->sub.trees.table;
|
||||
#ifdef DEBUG
|
||||
inflate_hufts = 0;
|
||||
#endif
|
||||
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
|
||||
s->sub.trees.blens, &bl, &bd, &tl, &td, z);
|
||||
s->sub.trees.blens, &bl, &bd, &tl, &td,
|
||||
s->hufts, z);
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
if (t != Z_OK)
|
||||
{
|
||||
if (t == (uInt)Z_DATA_ERROR)
|
||||
|
@ -321,19 +321,13 @@ int r;
|
|||
r = t;
|
||||
LEAVE
|
||||
}
|
||||
Tracev((stderr, "inflate: trees ok, %d * %d bytes used\n",
|
||||
inflate_hufts, sizeof(inflate_huft)));
|
||||
Tracev((stderr, "inflate: trees ok\n"));
|
||||
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
|
||||
{
|
||||
inflate_trees_free(td, z);
|
||||
inflate_trees_free(tl, z);
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->sub.decode.codes = c;
|
||||
s->sub.decode.tl = tl;
|
||||
s->sub.decode.td = td;
|
||||
}
|
||||
s->mode = CODES;
|
||||
case CODES:
|
||||
|
@ -342,8 +336,6 @@ int r;
|
|||
return inflate_flush(s, z, r);
|
||||
r = Z_OK;
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
inflate_trees_free(s->sub.decode.td, z);
|
||||
inflate_trees_free(s->sub.decode.tl, z);
|
||||
LOAD
|
||||
Tracev((stderr, "inflate: codes end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
|
@ -353,13 +345,6 @@ int r;
|
|||
s->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
if (k > 7) /* return unused byte, if any */
|
||||
{
|
||||
Assert(k < 16, "inflate_codes grabbed too many bytes")
|
||||
k -= 8;
|
||||
n++;
|
||||
p--; /* can always return one */
|
||||
}
|
||||
s->mode = DRY;
|
||||
case DRY:
|
||||
FLUSH
|
||||
|
@ -379,15 +364,15 @@ int r;
|
|||
}
|
||||
|
||||
|
||||
int inflate_blocks_free(s, z, c)
|
||||
int inflate_blocks_free(s, z)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
uLongf *c;
|
||||
{
|
||||
inflate_blocks_reset(s, z, c);
|
||||
inflate_blocks_reset(s, z, Z_NULL);
|
||||
ZFREE(z, s->window);
|
||||
ZFREE(z, s->hufts);
|
||||
ZFREE(z, s);
|
||||
Trace((stderr, "inflate: blocks freed\n"));
|
||||
Tracev((stderr, "inflate: blocks freed\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
@ -397,6 +382,17 @@ inflate_blocks_statef *s;
|
|||
const Bytef *d;
|
||||
uInt n;
|
||||
{
|
||||
zmemcpy((charf *)s->window, d, n);
|
||||
zmemcpy(s->window, d, n);
|
||||
s->read = s->write = s->window + n;
|
||||
}
|
||||
|
||||
|
||||
/* Returns true if inflate is currently at the end of a block generated
|
||||
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
||||
* IN assertion: s != Z_NULL
|
||||
*/
|
||||
int inflate_blocks_sync_point(s)
|
||||
inflate_blocks_statef *s;
|
||||
{
|
||||
return s->mode == LENS;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue