diff options
Diffstat (limited to 'deflate.c')
-rw-r--r-- | deflate.c | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -52,7 +52,7 @@ | |||
52 | #include "deflate.h" | 52 | #include "deflate.h" |
53 | 53 | ||
54 | const char deflate_copyright[] = | 54 | const char deflate_copyright[] = |
55 | " deflate 1.2.2.1 Copyright 1995-2004 Jean-loup Gailly "; | 55 | " deflate 1.2.2.2 Copyright 1995-2004 Jean-loup Gailly "; |
56 | /* | 56 | /* |
57 | If you use the zlib library in a product, an acknowledgment is welcome | 57 | If you use the zlib library in a product, an acknowledgment is welcome |
58 | in the documentation of your product. If for some reason you cannot | 58 | in the documentation of your product. If for some reason you cannot |
@@ -264,7 +264,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | |||
264 | #endif | 264 | #endif |
265 | if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || | 265 | if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || |
266 | windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || | 266 | windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || |
267 | strategy < 0 || strategy > Z_RLE) { | 267 | strategy < 0 || strategy > Z_FIXED) { |
268 | return Z_STREAM_ERROR; | 268 | return Z_STREAM_ERROR; |
269 | } | 269 | } |
270 | if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ | 270 | if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ |
@@ -432,7 +432,7 @@ int ZEXPORT deflateParams(strm, level, strategy) | |||
432 | #else | 432 | #else |
433 | if (level == Z_DEFAULT_COMPRESSION) level = 6; | 433 | if (level == Z_DEFAULT_COMPRESSION) level = 6; |
434 | #endif | 434 | #endif |
435 | if (level < 0 || level > 9 || strategy < 0 || strategy > Z_RLE) { | 435 | if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { |
436 | return Z_STREAM_ERROR; | 436 | return Z_STREAM_ERROR; |
437 | } | 437 | } |
438 | func = configuration_table[s->level].func; | 438 | func = configuration_table[s->level].func; |
@@ -573,7 +573,7 @@ int ZEXPORT deflate (strm, flush) | |||
573 | put_byte(s, s->level == 9 ? 2 : | 573 | put_byte(s, s->level == 9 ? 2 : |
574 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? | 574 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? |
575 | 4 : 0)); | 575 | 4 : 0)); |
576 | put_byte(s, 255); | 576 | put_byte(s, OS_CODE); |
577 | s->status = BUSY_STATE; | 577 | s->status = BUSY_STATE; |
578 | } | 578 | } |
579 | else { | 579 | else { |
@@ -892,12 +892,12 @@ int ZEXPORT deflateCopy (dest, source) | |||
892 | 892 | ||
893 | ss = source->state; | 893 | ss = source->state; |
894 | 894 | ||
895 | *dest = *source; | 895 | zmemcpy(dest, source, sizeof(z_stream)); |
896 | 896 | ||
897 | ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); | 897 | ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); |
898 | if (ds == Z_NULL) return Z_MEM_ERROR; | 898 | if (ds == Z_NULL) return Z_MEM_ERROR; |
899 | dest->state = (struct internal_state FAR *) ds; | 899 | dest->state = (struct internal_state FAR *) ds; |
900 | *ds = *ss; | 900 | zmemcpy(ds, ss, sizeof(deflate_state)); |
901 | ds->strm = dest; | 901 | ds->strm = dest; |
902 | 902 | ||
903 | ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); | 903 | ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); |
@@ -1057,7 +1057,12 @@ local uInt longest_match(s, cur_match) | |||
1057 | match = s->window + cur_match; | 1057 | match = s->window + cur_match; |
1058 | 1058 | ||
1059 | /* Skip to next match if the match length cannot increase | 1059 | /* Skip to next match if the match length cannot increase |
1060 | * or if the match length is less than 2: | 1060 | * or if the match length is less than 2. Note that the checks below |
1061 | * for insufficient lookahead only occur occasionally for performance | ||
1062 | * reasons. Therefore uninitialized memory will be accessed, and | ||
1063 | * conditional jumps will be made that depend on those values. | ||
1064 | * However the length of the match is limited to the lookahead, so | ||
1065 | * the output of deflate is not affected by the uninitialized values. | ||
1061 | */ | 1066 | */ |
1062 | #if (defined(UNALIGNED_OK) && MAX_MATCH == 258) | 1067 | #if (defined(UNALIGNED_OK) && MAX_MATCH == 258) |
1063 | /* This code assumes sizeof(unsigned short) == 2. Do not use | 1068 | /* This code assumes sizeof(unsigned short) == 2. Do not use |
@@ -1457,12 +1462,12 @@ local block_state deflate_fast(s, flush) | |||
1457 | * of the string with itself at the start of the input file). | 1462 | * of the string with itself at the start of the input file). |
1458 | */ | 1463 | */ |
1459 | #ifdef FASTEST | 1464 | #ifdef FASTEST |
1460 | if ((s->strategy < Z_HUFFMAN_ONLY) || | 1465 | if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) || |
1461 | (s->strategy == Z_RLE && s->strstart - hash_head == 1)) { | 1466 | (s->strategy == Z_RLE && s->strstart - hash_head == 1)) { |
1462 | s->match_length = longest_match_fast (s, hash_head); | 1467 | s->match_length = longest_match_fast (s, hash_head); |
1463 | } | 1468 | } |
1464 | #else | 1469 | #else |
1465 | if (s->strategy < Z_HUFFMAN_ONLY) { | 1470 | if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { |
1466 | s->match_length = longest_match (s, hash_head); | 1471 | s->match_length = longest_match (s, hash_head); |
1467 | } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { | 1472 | } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { |
1468 | s->match_length = longest_match_fast (s, hash_head); | 1473 | s->match_length = longest_match_fast (s, hash_head); |
@@ -1566,7 +1571,7 @@ local block_state deflate_slow(s, flush) | |||
1566 | * of window index 0 (in particular we have to avoid a match | 1571 | * of window index 0 (in particular we have to avoid a match |
1567 | * of the string with itself at the start of the input file). | 1572 | * of the string with itself at the start of the input file). |
1568 | */ | 1573 | */ |
1569 | if (s->strategy < Z_HUFFMAN_ONLY) { | 1574 | if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { |
1570 | s->match_length = longest_match (s, hash_head); | 1575 | s->match_length = longest_match (s, hash_head); |
1571 | } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { | 1576 | } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { |
1572 | s->match_length = longest_match_fast (s, hash_head); | 1577 | s->match_length = longest_match_fast (s, hash_head); |