diff options
Diffstat (limited to 'contrib/infback9')
| -rw-r--r-- | contrib/infback9/infback9.c | 13 | ||||
| -rw-r--r-- | contrib/infback9/inftree9.c | 21 | ||||
| -rw-r--r-- | contrib/infback9/inftree9.h | 24 |
3 files changed, 37 insertions, 21 deletions
diff --git a/contrib/infback9/infback9.c b/contrib/infback9/infback9.c index c5547ae..7bbe90c 100644 --- a/contrib/infback9/infback9.c +++ b/contrib/infback9/infback9.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* infback9.c -- inflate deflate64 data using a call-back interface | 1 | /* infback9.c -- inflate deflate64 data using a call-back interface |
| 2 | * Copyright (C) 1995-2006 Mark Adler | 2 | * Copyright (C) 1995-2008 Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -433,7 +433,16 @@ void FAR *out_desc; | |||
| 433 | /* handle error breaks in while */ | 433 | /* handle error breaks in while */ |
| 434 | if (mode == BAD) break; | 434 | if (mode == BAD) break; |
| 435 | 435 | ||
| 436 | /* build code tables */ | 436 | /* check for end-of-block code (better have one) */ |
| 437 | if (state->lens[256] == 0) { | ||
| 438 | strm->msg = (char *)"invalid code -- missing end-of-block"; | ||
| 439 | mode = BAD; | ||
| 440 | break; | ||
| 441 | } | ||
| 442 | |||
| 443 | /* build code tables -- note: do not change the lenbits or distbits | ||
| 444 | values here (9 and 6) without reading the comments in inftree9.h | ||
| 445 | concerning the ENOUGH constants, which depend on those values */ | ||
| 437 | state->next = state->codes; | 446 | state->next = state->codes; |
| 438 | lencode = (code const FAR *)(state->next); | 447 | lencode = (code const FAR *)(state->next); |
| 439 | lenbits = 9; | 448 | lenbits = 9; |
diff --git a/contrib/infback9/inftree9.c b/contrib/infback9/inftree9.c index c24302b..18353cb 100644 --- a/contrib/infback9/inftree9.c +++ b/contrib/infback9/inftree9.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* inftree9.c -- generate Huffman trees for efficient decoding | 1 | /* inftree9.c -- generate Huffman trees for efficient decoding |
| 2 | * Copyright (C) 1995-2006 Mark Adler | 2 | * Copyright (C) 1995-2008 Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -9,7 +9,7 @@ | |||
| 9 | #define MAXBITS 15 | 9 | #define MAXBITS 15 |
| 10 | 10 | ||
| 11 | const char inflate9_copyright[] = | 11 | const char inflate9_copyright[] = |
| 12 | " inflate9 1.2.3.3 Copyright 1995-2006 Mark Adler "; | 12 | " inflate9 1.2.3.4 Copyright 1995-2008 Mark Adler "; |
| 13 | /* | 13 | /* |
| 14 | If you use the zlib library in a product, an acknowledgment is welcome | 14 | If you use the zlib library in a product, an acknowledgment is welcome |
| 15 | in the documentation of your product. If for some reason you cannot | 15 | in the documentation of your product. If for some reason you cannot |
| @@ -64,7 +64,7 @@ unsigned short FAR *work; | |||
| 64 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ | 64 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ |
| 65 | 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, | 65 | 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, |
| 66 | 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, | 66 | 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, |
| 67 | 133, 133, 133, 133, 144, 201, 203}; | 67 | 133, 133, 133, 133, 144, 72, 200}; |
| 68 | static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ | 68 | static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ |
| 69 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, | 69 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, |
| 70 | 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, | 70 | 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, |
| @@ -160,11 +160,10 @@ unsigned short FAR *work; | |||
| 160 | entered in the tables. | 160 | entered in the tables. |
| 161 | 161 | ||
| 162 | used keeps track of how many table entries have been allocated from the | 162 | used keeps track of how many table entries have been allocated from the |
| 163 | provided *table space. It is checked when a LENS table is being made | 163 | provided *table space. It is checked for LENS and DIST tables against |
| 164 | against the space in *table, ENOUGH, minus the maximum space needed by | 164 | the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in |
| 165 | the worst case distance code, MAXD. This should never happen, but the | 165 | the initial root table size constants. See the comments in inftree9.h |
| 166 | sufficiency of ENOUGH has not been proven exhaustively, hence the check. | 166 | for more information. |
| 167 | This assumes that when type == LENS, bits == 9. | ||
| 168 | 167 | ||
| 169 | sym increments through all symbols, and the loop terminates when | 168 | sym increments through all symbols, and the loop terminates when |
| 170 | all codes of length max, i.e. all codes, have been processed. This | 169 | all codes of length max, i.e. all codes, have been processed. This |
| @@ -203,7 +202,8 @@ unsigned short FAR *work; | |||
| 203 | mask = used - 1; /* mask for comparing low */ | 202 | mask = used - 1; /* mask for comparing low */ |
| 204 | 203 | ||
| 205 | /* check available table space */ | 204 | /* check available table space */ |
| 206 | if (type == LENS && used >= ENOUGH - MAXD) | 205 | if ((type == LENS && used >= ENOUGH_LENS) || |
| 206 | (type == DISTS && used >= ENOUGH_DISTS)) | ||
| 207 | return 1; | 207 | return 1; |
| 208 | 208 | ||
| 209 | /* process all codes and make table entries */ | 209 | /* process all codes and make table entries */ |
| @@ -270,7 +270,8 @@ unsigned short FAR *work; | |||
| 270 | 270 | ||
| 271 | /* check for enough space */ | 271 | /* check for enough space */ |
| 272 | used += 1U << curr; | 272 | used += 1U << curr; |
| 273 | if (type == LENS && used >= ENOUGH - MAXD) | 273 | if ((type == LENS && used >= ENOUGH_LENS) || |
| 274 | (type == DISTS && used >= ENOUGH_DISTS)) | ||
| 274 | return 1; | 275 | return 1; |
| 275 | 276 | ||
| 276 | /* point entry in root table to sub-table */ | 277 | /* point entry in root table to sub-table */ |
diff --git a/contrib/infback9/inftree9.h b/contrib/infback9/inftree9.h index a268084..5ab21f0 100644 --- a/contrib/infback9/inftree9.h +++ b/contrib/infback9/inftree9.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* inftree9.h -- header to use inftree9.c | 1 | /* inftree9.h -- header to use inftree9.c |
| 2 | * Copyright (C) 1995-2003 Mark Adler | 2 | * Copyright (C) 1995-2008 Mark Adler |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -35,15 +35,21 @@ typedef struct { | |||
| 35 | 01000000 - invalid code | 35 | 01000000 - invalid code |
| 36 | */ | 36 | */ |
| 37 | 37 | ||
| 38 | /* Maximum size of dynamic tree. The maximum found in a long but non- | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is |
| 39 | exhaustive search was 1444 code structures (852 for length/literals | 39 | 1446, which is the sum of 852 for literal/length codes and 594 for distance |
| 40 | and 592 for distances, the latter actually the result of an | 40 | codes. These values were found by exhaustive searches using the program |
| 41 | exhaustive search). The true maximum is not known, but the value | 41 | examples/enough.c found in the zlib distribtution. The arguments to that |
| 42 | below is more than safe. */ | 42 | program are the number of symbols, the initial root table size, and the |
| 43 | #define ENOUGH 2048 | 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes |
| 44 | #define MAXD 592 | 44 | returns returns 852, and "enough 32 6 15" for distance codes returns 594. |
| 45 | The initial root table size (9 or 6) is found in the fifth argument of the | ||
| 46 | inflate_table() calls in infback9.c. If the root table size is changed, | ||
| 47 | then these maximum sizes would be need to be recalculated and updated. */ | ||
| 48 | #define ENOUGH_LENS 852 | ||
| 49 | #define ENOUGH_DISTS 594 | ||
| 50 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) | ||
| 45 | 51 | ||
| 46 | /* Type of code to build for inftable() */ | 52 | /* Type of code to build for inflate_table9() */ |
| 47 | typedef enum { | 53 | typedef enum { |
| 48 | CODES, | 54 | CODES, |
| 49 | LENS, | 55 | LENS, |
