Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: third_party/zlib/mixed-source.patch

Issue 2079313002: Revert of Update Zlib to version 1.2.8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/zlib/inftrees.c ('k') | third_party/zlib/mozzconf.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 diff --git a/third_party/zlib/deflate.c b/third_party/zlib/deflate.c 1 diff --git a/third_party/zlib/deflate.c b/third_party/zlib/deflate.c
2 index 6969577..7c95b30 100644 2 index 5c4022f..88b2ec0 100644
3 --- a/third_party/zlib/deflate.c 3 --- a/third_party/zlib/deflate.c
4 +++ b/third_party/zlib/deflate.c 4 +++ b/third_party/zlib/deflate.c
5 @@ -70,14 +70,15 @@ typedef enum { 5 @@ -70,14 +70,15 @@ typedef enum {
6 finish_done /* finish done, accept no more input or output */ 6 finish_done /* finish done, accept no more input or output */
7 } block_state; 7 } block_state;
8 8
9 -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); 9 -typedef block_state (*compress_func) OF((deflate_state *s, int flush));
10 +typedef block_state (*compress_func) OF((deflate_state *s, int flush, 10 +typedef block_state (*compress_func) OF((deflate_state *s, int flush,
11 + int clas)); 11 + int clas));
12 /* Compression function. Returns the block state after the call. */ 12 /* Compression function. Returns the block state after the call. */
(...skipping 14 matching lines...) Expand all
27 #ifdef ASMV 27 #ifdef ASMV
28 void match_init OF((void)); /* asm code initialization */ 28 void match_init OF((void)); /* asm code initialization */
29 - uInt longest_match OF((deflate_state *s, IPos cur_match)); 29 - uInt longest_match OF((deflate_state *s, IPos cur_match));
30 + uInt longest_match OF((deflate_state *s, IPos cur_match, int clas)); 30 + uInt longest_match OF((deflate_state *s, IPos cur_match, int clas));
31 #else 31 #else
32 -local uInt longest_match OF((deflate_state *s, IPos cur_match)); 32 -local uInt longest_match OF((deflate_state *s, IPos cur_match));
33 +local uInt longest_match OF((deflate_state *s, IPos cur_match, int clas)); 33 +local uInt longest_match OF((deflate_state *s, IPos cur_match, int clas));
34 #endif 34 #endif
35 35
36 #ifdef DEBUG 36 #ifdef DEBUG
37 @@ -293,6 +294,9 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, m emLevel, strategy, 37 @@ -281,6 +282,9 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, m emLevel, strategy,
38 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); 38 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
39 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); 39 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
40 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); 40 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
41 + s->class_bitmap = NULL; 41 + s->class_bitmap = NULL;
42 + zmemzero(&s->cookie_locations, sizeof(s->cookie_locations)); 42 + zmemzero(&s->cookie_locations, sizeof(s->cookie_locations));
43 + strm->clas = 0; 43 + strm->clas = 0;
44 44
45 s->high_water = 0; /* nothing written to s->window yet */ 45 s->high_water = 0; /* nothing written to s->window yet */
46 46
47 @@ -406,6 +410,8 @@ int ZEXPORT deflateResetKeep (strm) 47 @@ -367,6 +371,8 @@ int ZEXPORT deflateReset (strm)
48 s = (deflate_state *)strm->state; 48 s = (deflate_state *)strm->state;
49 s->pending = 0; 49 s->pending = 0;
50 s->pending_out = s->pending_buf; 50 s->pending_out = s->pending_buf;
51 + TRY_FREE(strm, s->class_bitmap); 51 + TRY_FREE(strm, s->class_bitmap);
52 + s->class_bitmap = NULL; 52 + s->class_bitmap = NULL;
53 53
54 if (s->wrap < 0) { 54 if (s->wrap < 0) {
55 s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ 55 s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
56 @@ -900,9 +906,26 @@ int ZEXPORT deflate (strm, flush) 56 @@ -817,9 +823,26 @@ int ZEXPORT deflate (strm, flush)
57 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { 57 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
58 block_state bstate; 58 block_state bstate;
59 59
60 - bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : 60 - bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
61 - (s->strategy == Z_RLE ? deflate_rle(s, flush) : 61 - (s->strategy == Z_RLE ? deflate_rle(s, flush) :
62 - (*(configuration_table[s->level].func))(s, flush)); 62 - (*(configuration_table[s->level].func))(s, flush));
63 + if (strm->clas && s->class_bitmap == NULL) { 63 + if (strm->clas && s->class_bitmap == NULL) {
64 + /* This is the first time that we have seen alternative class 64 + /* This is the first time that we have seen alternative class
65 + * data. All data up till this point has been standard class. */ 65 + * data. All data up till this point has been standard class. */
66 + s->class_bitmap = (Bytef*) ZALLOC(strm, s->w_size/4, sizeof(Byte)); 66 + s->class_bitmap = (Bytef*) ZALLOC(strm, s->w_size/4, sizeof(Byte));
67 + zmemzero(s->class_bitmap, s->w_size/4); 67 + zmemzero(s->class_bitmap, s->w_size/4);
68 + } 68 + }
69 + 69 +
70 + if (strm->clas && s->strategy == Z_RLE) { 70 + if (strm->clas && s->strategy == Z_RLE) {
71 + /* We haven't patched deflate_rle. */ 71 + /* We haven't patched deflate_rle. */
72 + ERR_RETURN(strm, Z_BUF_ERROR); 72 + ERR_RETURN(strm, Z_BUF_ERROR);
73 + } 73 + }
74 + 74 +
75 + if (s->strategy == Z_HUFFMAN_ONLY) { 75 + if (s->strategy == Z_HUFFMAN_ONLY) {
76 + bstate = deflate_huff(s, flush); 76 + bstate = deflate_huff(s, flush);
77 + } else if (s->strategy == Z_RLE) { 77 + } else if (s->strategy == Z_RLE) {
78 + bstate = deflate_rle(s, flush); 78 + bstate = deflate_rle(s, flush);
79 + } else { 79 + } else {
80 + bstate = (*(configuration_table[s->level].func)) 80 + bstate = (*(configuration_table[s->level].func))
81 + (s, flush, strm->clas); 81 + (s, flush, strm->clas);
82 + } 82 + }
83 83
84 if (bstate == finish_started || bstate == finish_done) { 84 if (bstate == finish_started || bstate == finish_done) {
85 s->status = FINISH_STATE; 85 s->status = FINISH_STATE;
86 @@ -999,6 +1022,7 @@ int ZEXPORT deflateEnd (strm) 86 @@ -915,6 +938,7 @@ int ZEXPORT deflateEnd (strm)
87 TRY_FREE(strm, strm->state->head); 87 TRY_FREE(strm, strm->state->head);
88 TRY_FREE(strm, strm->state->prev); 88 TRY_FREE(strm, strm->state->prev);
89 TRY_FREE(strm, strm->state->window); 89 TRY_FREE(strm, strm->state->window);
90 + TRY_FREE(strm, strm->state->class_bitmap); 90 + TRY_FREE(strm, strm->state->class_bitmap);
91 91
92 ZFREE(strm, strm->state); 92 ZFREE(strm, strm->state);
93 strm->state = Z_NULL; 93 strm->state = Z_NULL;
94 @@ -1131,6 +1155,57 @@ local void lm_init (s) 94 @@ -1046,6 +1070,57 @@ local void lm_init (s)
95 #endif 95 #endif
96 } 96 }
97 97
98 +/* class_set sets bits [offset,offset+len) in s->class_bitmap to either 1 (if 98 +/* class_set sets bits [offset,offset+len) in s->class_bitmap to either 1 (if
99 + * class != 0) or 0 (otherwise). */ 99 + * class != 0) or 0 (otherwise). */
100 +local void class_set(s, offset, len, clas) 100 +local void class_set(s, offset, len, clas)
101 + deflate_state *s; 101 + deflate_state *s;
102 + IPos offset; 102 + IPos offset;
103 + uInt len; 103 + uInt len;
104 + int clas; 104 + int clas;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 + IPos window_offset; 142 + IPos window_offset;
143 +{ 143 +{
144 + IPos byte = window_offset >> 3; 144 + IPos byte = window_offset >> 3;
145 + IPos bit = window_offset & 7; 145 + IPos bit = window_offset & 7;
146 + return (s->class_bitmap[byte] >> bit) & 1; 146 + return (s->class_bitmap[byte] >> bit) & 1;
147 +} 147 +}
148 + 148 +
149 #ifndef FASTEST 149 #ifndef FASTEST
150 /* =========================================================================== 150 /* ===========================================================================
151 * Set match_start to the longest match starting at the given string and 151 * Set match_start to the longest match starting at the given string and
152 @@ -1145,9 +1220,10 @@ local void lm_init (s) 152 @@ -1060,9 +1135,10 @@ local void lm_init (s)
153 /* For 80x86 and 680x0, an optimized version will be provided in match.asm or 153 /* For 80x86 and 680x0, an optimized version will be provided in match.asm or
154 * match.S. The code will be functionally equivalent. 154 * match.S. The code will be functionally equivalent.
155 */ 155 */
156 -local uInt longest_match(s, cur_match) 156 -local uInt longest_match(s, cur_match)
157 +local uInt longest_match(s, cur_match, clas) 157 +local uInt longest_match(s, cur_match, clas)
158 deflate_state *s; 158 deflate_state *s;
159 IPos cur_match; /* current match */ 159 IPos cur_match; /* current match */
160 + int clas; 160 + int clas;
161 { 161 {
162 unsigned chain_length = s->max_chain_length;/* max hash chain length */ 162 unsigned chain_length = s->max_chain_length;/* max hash chain length */
163 register Bytef *scan = s->window + s->strstart; /* current string */ 163 register Bytef *scan = s->window + s->strstart; /* current string */
164 @@ -1195,6 +1271,9 @@ local uInt longest_match(s, cur_match) 164 @@ -1110,6 +1186,9 @@ local uInt longest_match(s, cur_match)
165 do { 165 do {
166 Assert(cur_match < s->strstart, "no future"); 166 Assert(cur_match < s->strstart, "no future");
167 match = s->window + cur_match; 167 match = s->window + cur_match;
168 + /* If the matched data is in the wrong class, skip it. */ 168 + /* If the matched data is in the wrong class, skip it. */
169 + if (s->class_bitmap && class_at(s, cur_match) != clas) 169 + if (s->class_bitmap && class_at(s, cur_match) != clas)
170 + continue; 170 + continue;
171 171
172 /* Skip to next match if the match length cannot increase 172 /* Skip to next match if the match length cannot increase
173 * or if the match length is less than 2. Note that the checks below 173 * or if the match length is less than 2. Note that the checks below
174 @@ -1237,6 +1316,8 @@ local uInt longest_match(s, cur_match) 174 @@ -1152,6 +1231,8 @@ local uInt longest_match(s, cur_match)
175 len = (MAX_MATCH - 1) - (int)(strend-scan); 175 len = (MAX_MATCH - 1) - (int)(strend-scan);
176 scan = strend - (MAX_MATCH-1); 176 scan = strend - (MAX_MATCH-1);
177 177
178 +#error "UNALIGNED_OK hasn't been patched." 178 +#error "UNALIGNED_OK hasn't been patched."
179 + 179 +
180 #else /* UNALIGNED_OK */ 180 #else /* UNALIGNED_OK */
181 181
182 if (match[best_len] != scan_end || 182 if (match[best_len] != scan_end ||
183 @@ -1253,15 +1334,23 @@ local uInt longest_match(s, cur_match) 183 @@ -1168,15 +1249,23 @@ local uInt longest_match(s, cur_match)
184 scan += 2, match++; 184 scan += 2, match++;
185 Assert(*scan == *match, "match[2]?"); 185 Assert(*scan == *match, "match[2]?");
186 186
187 - /* We check for insufficient lookahead only every 8th comparison; 187 - /* We check for insufficient lookahead only every 8th comparison;
188 - * the 256th check will be made at strstart+258. 188 - * the 256th check will be made at strstart+258.
189 - */ 189 - */
190 - do { 190 - do {
191 - } while (*++scan == *++match && *++scan == *++match && 191 - } while (*++scan == *++match && *++scan == *++match &&
192 - *++scan == *++match && *++scan == *++match && 192 - *++scan == *++match && *++scan == *++match &&
193 - *++scan == *++match && *++scan == *++match && 193 - *++scan == *++match && *++scan == *++match &&
(...skipping 12 matching lines...) Expand all
206 + } else { 206 + } else {
207 + /* We have to be mindful of the class of the data and not stray. */ 207 + /* We have to be mindful of the class of the data and not stray. */
208 + do { 208 + do {
209 + } while (*++scan == *++match && 209 + } while (*++scan == *++match &&
210 + class_at(s, match - s->window) == clas && 210 + class_at(s, match - s->window) == clas &&
211 + scan < strend); 211 + scan < strend);
212 + } 212 + }
213 213
214 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 214 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
215 215
216 @@ -1289,20 +1378,74 @@ local uInt longest_match(s, cur_match) 216 @@ -1204,20 +1293,74 @@ local uInt longest_match(s, cur_match)
217 } 217 }
218 #endif /* ASMV */ 218 #endif /* ASMV */
219 219
220 +/* cookie_match is a replacement for longest_match in the case of cookie data. 220 +/* cookie_match is a replacement for longest_match in the case of cookie data.
221 + * Here we only wish to match the entire value so trying the partial matches in 221 + * Here we only wish to match the entire value so trying the partial matches in
222 + * longest_match is both wasteful and often fails to find the correct match. 222 + * longest_match is both wasteful and often fails to find the correct match.
223 + * 223 + *
224 + * So we take the djb2 hash of the cookie and look up the last position for a 224 + * So we take the djb2 hash of the cookie and look up the last position for a
225 + * match in a special hash table. */ 225 + * match in a special hash table. */
226 +local uInt cookie_match(s, start, len) 226 +local uInt cookie_match(s, start, len)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 register Bytef *scan = s->window + s->strstart; /* current string */ 282 register Bytef *scan = s->window + s->strstart; /* current string */
283 register Bytef *match; /* matched string */ 283 register Bytef *match; /* matched string */
284 register int len; /* length of current match */ 284 register int len; /* length of current match */
285 register Bytef *strend = s->window + s->strstart + MAX_MATCH; 285 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
286 286
287 +#error "This code not patched" 287 +#error "This code not patched"
288 + 288 +
289 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. 289 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
290 * It is easy to get rid of this optimization if necessary. 290 * It is easy to get rid of this optimization if necessary.
291 */ 291 */
292 @@ -1447,6 +1590,20 @@ local void fill_window(s) 292 @@ -1360,6 +1503,21 @@ local void fill_window(s)
293 */ 293 */
294 } while (--n); 294 } while (--n);
295 #endif 295 #endif
296 +
296 + for (n = 0; n < Z_COOKIE_HASH_SIZE; n++) { 297 + for (n = 0; n < Z_COOKIE_HASH_SIZE; n++) {
297 + if (s->cookie_locations[n] > wsize) { 298 + if (s->cookie_locations[n] > wsize) {
298 + s->cookie_locations[n] -= wsize; 299 + s->cookie_locations[n] -= wsize;
299 + } else { 300 + } else {
300 + s->cookie_locations[n] = 0; 301 + s->cookie_locations[n] = 0;
301 + } 302 + }
302 + } 303 + }
303 + 304 +
304 + if (s->class_bitmap) { 305 + if (s->class_bitmap) {
305 + zmemcpy(s->class_bitmap, s->class_bitmap + s->w_size/8, 306 + zmemcpy(s->class_bitmap, s->class_bitmap + s->w_size/8,
306 + s->w_size/8); 307 + s->w_size/8);
307 + zmemzero(s->class_bitmap + s->w_size/8, s->w_size/8); 308 + zmemzero(s->class_bitmap + s->w_size/8, s->w_size/8);
308 + } 309 + }
309 + 310 +
310 more += wsize; 311 more += wsize;
311 } 312 }
312 if (s->strm->avail_in == 0) break; 313 if (s->strm->avail_in == 0) return;
313 @@ -1465,6 +1622,9 @@ local void fill_window(s) 314 @@ -1378,6 +1536,9 @@ local void fill_window(s)
314 Assert(more >= 2, "more < 2"); 315 Assert(more >= 2, "more < 2");
315 316
316 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); 317 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
317 + if (s->class_bitmap != NULL) { 318 + if (s->class_bitmap != NULL) {
318 + class_set(s, s->strstart + s->lookahead, n, s->strm->clas); 319 + class_set(s, s->strstart + s->lookahead, n, s->strm->clas);
319 + } 320 + }
320 s->lookahead += n; 321 s->lookahead += n;
321 322
322 /* Initialize the hash value now that we have some input: */ 323 /* Initialize the hash value now that we have some input: */
323 @@ -1561,9 +1721,10 @@ local void fill_window(s) 324 @@ -1459,9 +1620,10 @@ local void fill_window(s)
324 * NOTE: this function should be optimized to avoid extra copying from 325 * NOTE: this function should be optimized to avoid extra copying from
325 * window to pending_buf. 326 * window to pending_buf.
326 */ 327 */
327 -local block_state deflate_stored(s, flush) 328 -local block_state deflate_stored(s, flush)
328 +local block_state deflate_stored(s, flush, clas) 329 +local block_state deflate_stored(s, flush, clas)
329 deflate_state *s; 330 deflate_state *s;
330 int flush; 331 int flush;
331 + int clas; 332 + int clas;
332 { 333 {
333 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited 334 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
334 * to pending_buf_size, and each stored block has a 5 byte header: 335 * to pending_buf_size, and each stored block has a 5 byte header:
335 @@ -1625,13 +1786,19 @@ local block_state deflate_stored(s, flush) 336 @@ -1517,13 +1679,19 @@ local block_state deflate_stored(s, flush)
336 * new strings in the dictionary only for unmatched strings or for short 337 * new strings in the dictionary only for unmatched strings or for short
337 * matches. It is used only for the fast compression options. 338 * matches. It is used only for the fast compression options.
338 */ 339 */
339 -local block_state deflate_fast(s, flush) 340 -local block_state deflate_fast(s, flush)
340 +local block_state deflate_fast(s, flush, clas) 341 +local block_state deflate_fast(s, flush, clas)
341 deflate_state *s; 342 deflate_state *s;
342 int flush; 343 int flush;
343 + int clas; 344 + int clas;
344 { 345 {
345 IPos hash_head; /* head of the hash chain */ 346 IPos hash_head; /* head of the hash chain */
346 int bflush; /* set if current block must be flushed */ 347 int bflush; /* set if current block must be flushed */
347 348
348 + if (clas != 0) { 349 + if (clas != 0) {
349 + /* We haven't patched this code for alternative class data. */ 350 + /* We haven't patched this code for alternative class data. */
350 + return Z_BUF_ERROR; 351 + return Z_BUF_ERROR;
351 + } 352 + }
352 + 353 +
353 for (;;) { 354 for (;;) {
354 /* Make sure that we always have enough lookahead, except 355 /* Make sure that we always have enough lookahead, except
355 * at the end of the input file. We need MAX_MATCH bytes 356 * at the end of the input file. We need MAX_MATCH bytes
356 @@ -1662,7 +1829,7 @@ local block_state deflate_fast(s, flush) 357 @@ -1554,7 +1722,7 @@ local block_state deflate_fast(s, flush)
357 * of window index 0 (in particular we have to avoid a match 358 * of window index 0 (in particular we have to avoid a match
358 * of the string with itself at the start of the input file). 359 * of the string with itself at the start of the input file).
359 */ 360 */
360 - s->match_length = longest_match (s, hash_head); 361 - s->match_length = longest_match (s, hash_head);
361 + s->match_length = longest_match (s, hash_head, clas); 362 + s->match_length = longest_match (s, hash_head, clas);
362 /* longest_match() sets match_start */ 363 /* longest_match() sets match_start */
363 } 364 }
364 if (s->match_length >= MIN_MATCH) { 365 if (s->match_length >= MIN_MATCH) {
365 @@ -1727,12 +1894,25 @@ local block_state deflate_fast(s, flush) 366 @@ -1613,12 +1781,25 @@ local block_state deflate_fast(s, flush)
366 * evaluation for matches: a match is finally adopted only if there is 367 * evaluation for matches: a match is finally adopted only if there is
367 * no better match at the next window position. 368 * no better match at the next window position.
368 */ 369 */
369 -local block_state deflate_slow(s, flush) 370 -local block_state deflate_slow(s, flush)
370 +local block_state deflate_slow(s, flush, clas) 371 +local block_state deflate_slow(s, flush, clas)
371 deflate_state *s; 372 deflate_state *s;
372 int flush; 373 int flush;
373 + int clas; 374 + int clas;
374 { 375 {
375 IPos hash_head; /* head of hash chain */ 376 IPos hash_head; /* head of hash chain */
376 int bflush; /* set if current block must be flushed */ 377 int bflush; /* set if current block must be flushed */
377 + uInt input_length ; 378 + uInt input_length ;
378 + int first = 1; /* first says whether this is the first iteration 379 + int first = 1; /* first says whether this is the first iteration
379 + of the loop, below. */ 380 + of the loop, below. */
380 + 381 +
381 + if (clas == Z_CLASS_COOKIE) { 382 + if (clas == Z_CLASS_COOKIE) {
382 + if (s->lookahead) { 383 + if (s->lookahead) {
383 + /* Alternative class data must always be presented at the beginning 384 + /* Alternative class data must always be presented at the beginning
384 + * of a block. */ 385 + * of a block. */
385 + return Z_BUF_ERROR; 386 + return Z_BUF_ERROR;
386 + } 387 + }
387 + input_length = s->strm->avail_in; 388 + input_length = s->strm->avail_in;
388 + } 389 + }
389 390
390 /* Process the input block. */ 391 /* Process the input block. */
391 for (;;) { 392 for (;;) {
392 @@ -1762,13 +1942,18 @@ local block_state deflate_slow(s, flush) 393 @@ -1648,13 +1829,18 @@ local block_state deflate_slow(s, flush)
393 s->prev_length = s->match_length, s->prev_match = s->match_start; 394 s->prev_length = s->match_length, s->prev_match = s->match_start;
394 s->match_length = MIN_MATCH-1; 395 s->match_length = MIN_MATCH-1;
395 396
396 - if (hash_head != NIL && s->prev_length < s->max_lazy_match && 397 - if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
397 - s->strstart - hash_head <= MAX_DIST(s)) { 398 - s->strstart - hash_head <= MAX_DIST(s)) {
398 + if (clas == Z_CLASS_COOKIE && first) { 399 + if (clas == Z_CLASS_COOKIE && first) {
399 + s->match_length = cookie_match(s, s->strstart, input_length); 400 + s->match_length = cookie_match(s, s->strstart, input_length);
400 + } else if (clas == Z_CLASS_STANDARD && 401 + } else if (clas == Z_CLASS_STANDARD &&
401 + hash_head != NIL && 402 + hash_head != NIL &&
402 + s->prev_length < s->max_lazy_match && 403 + s->prev_length < s->max_lazy_match &&
403 + s->strstart - hash_head <= MAX_DIST(s)) { 404 + s->strstart - hash_head <= MAX_DIST(s)) {
404 /* To simplify the code, we prevent matches with the string 405 /* To simplify the code, we prevent matches with the string
405 * of window index 0 (in particular we have to avoid a match 406 * of window index 0 (in particular we have to avoid a match
406 * of the string with itself at the start of the input file). 407 * of the string with itself at the start of the input file).
407 */ 408 */
408 - s->match_length = longest_match (s, hash_head); 409 - s->match_length = longest_match (s, hash_head);
409 + s->match_length = longest_match (s, hash_head, clas); 410 + s->match_length = longest_match (s, hash_head, clas);
410 + 411 +
411 /* longest_match() sets match_start */ 412 /* longest_match() sets match_start */
412 413
413 if (s->match_length <= 5 && (s->strategy == Z_FILTERED 414 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
414 @@ -1787,7 +1972,20 @@ local block_state deflate_slow(s, flush) 415 @@ -1673,7 +1859,20 @@ local block_state deflate_slow(s, flush)
415 /* If there was a match at the previous step and the current 416 /* If there was a match at the previous step and the current
416 * match is not better, output the previous match: 417 * match is not better, output the previous match:
417 */ 418 */
418 - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { 419 - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
419 + first = 0; 420 + first = 0;
420 + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length && 421 + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length &&
421 + /* We will only accept an exact match for Z_CLASS_COOKIE data and 422 + /* We will only accept an exact match for Z_CLASS_COOKIE data and
422 + * we won't match Z_CLASS_HUFFMAN_ONLY data at all. */ 423 + * we won't match Z_CLASS_HUFFMAN_ONLY data at all. */
423 + (clas == Z_CLASS_STANDARD || (clas == Z_CLASS_COOKIE && 424 + (clas == Z_CLASS_STANDARD || (clas == Z_CLASS_COOKIE &&
424 + s->prev_length == input_length && 425 + s->prev_length == input_length &&
425 + s->prev_match > 0 && 426 + s->prev_match > 0 &&
426 + /* We require that a Z_CLASS_COOKIE match be 427 + /* We require that a Z_CLASS_COOKIE match be
427 + * preceded by either a semicolon (which cannot be 428 + * preceded by either a semicolon (which cannot be
428 + * part of a cookie), or non-cookie data. This is 429 + * part of a cookie), or non-cookie data. This is
429 + * to prevent a cookie from being a suffix of 430 + * to prevent a cookie from being a suffix of
430 + * another. */ 431 + * another. */
431 + (class_at(s, s->prev_match-1) == Z_CLASS_STANDARD | | 432 + (class_at(s, s->prev_match-1) == Z_CLASS_STANDARD | |
432 + *(s->window + s->prev_match-1) == ';')))) { 433 + *(s->window + s->prev_match-1) == ';')))) {
433 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; 434 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
434 /* Do not insert strings in hash table beyond this. */ 435 /* Do not insert strings in hash table beyond this. */
435 436
436 diff --git a/third_party/zlib/deflate.h b/third_party/zlib/deflate.h 437 diff --git a/third_party/zlib/deflate.h b/third_party/zlib/deflate.h
437 index ce0299e..c795034 100644 438 index cbf0d1e..2fe6fd6 100644
438 --- a/third_party/zlib/deflate.h 439 --- a/third_party/zlib/deflate.h
439 +++ b/third_party/zlib/deflate.h 440 +++ b/third_party/zlib/deflate.h
440 @@ -94,6 +94,9 @@ typedef unsigned IPos; 441 @@ -91,6 +91,9 @@ typedef unsigned IPos;
441 * save space in the various tables. IPos is used only for parameter passing. 442 * save space in the various tables. IPos is used only for parameter passing.
442 */ 443 */
443 444
444 +#define Z_COOKIE_HASH_SIZE 256 445 +#define Z_COOKIE_HASH_SIZE 256
445 +#define Z_COOKIE_HASH_MASK (Z_COOKIE_HASH_SIZE-1) 446 +#define Z_COOKIE_HASH_MASK (Z_COOKIE_HASH_SIZE-1)
446 + 447 +
447 typedef struct internal_state { 448 typedef struct internal_state {
448 z_streamp strm; /* pointer back to this zlib stream */ 449 z_streamp strm; /* pointer back to this zlib stream */
449 int status; /* as the name implies */ 450 int status; /* as the name implies */
450 @@ -142,6 +145,8 @@ typedef struct internal_state { 451 @@ -139,6 +142,8 @@ typedef struct internal_state {
451 uInt hash_mask; /* hash_size-1 */ 452 uInt hash_mask; /* hash_size-1 */
452 453
453 uInt hash_shift; 454 uInt hash_shift;
454 + Bytef *class_bitmap; /* bitmap of class for each byte in window */ 455 + Bytef *class_bitmap; /* bitmap of class for each byte in window */
455 + IPos cookie_locations[Z_COOKIE_HASH_SIZE]; 456 + IPos cookie_locations[Z_COOKIE_HASH_SIZE];
456 /* Number of bits by which ins_h must be shifted at each input 457 /* Number of bits by which ins_h must be shifted at each input
457 * step. It must be such that after MIN_MATCH steps, the oldest 458 * step. It must be such that after MIN_MATCH steps, the oldest
458 * byte no longer takes part in the hash key, that is: 459 * byte no longer takes part in the hash key, that is:
459 diff --git a/third_party/zlib/zlib.h b/third_party/zlib/zlib.h 460 diff --git a/third_party/zlib/zlib.h b/third_party/zlib/zlib.h
460 index 36c73af..5544c88 100644 461 index 4d54af9..da7e971 100644
461 --- a/third_party/zlib/zlib.h 462 --- a/third_party/zlib/zlib.h
462 +++ b/third_party/zlib/zlib.h 463 +++ b/third_party/zlib/zlib.h
463 @@ -101,6 +101,7 @@ typedef struct z_stream_s { 464 @@ -101,6 +101,7 @@ typedef struct z_stream_s {
464 int data_type; /* best guess about the data type: binary or text */ 465 int data_type; /* best guess about the data type: binary or text */
465 uLong adler; /* adler32 value of the uncompressed data */ 466 uLong adler; /* adler32 value of the uncompressed data */
466 uLong reserved; /* reserved for future use */ 467 uLong reserved; /* reserved for future use */
467 + int clas; 468 + int clas;
468 } z_stream; 469 } z_stream;
469 470
470 typedef z_stream FAR *z_streamp; 471 typedef z_stream FAR *z_streamp;
471 @@ -207,6 +208,10 @@ typedef gz_header FAR *gz_headerp; 472 @@ -207,6 +208,10 @@ typedef gz_header FAR *gz_headerp;
472 473
473 #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 474 #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
474 475
475 +#define Z_CLASS_STANDARD 0 476 +#define Z_CLASS_STANDARD 0
476 +#define Z_CLASS_COOKIE 1 477 +#define Z_CLASS_COOKIE 1
477 +#define Z_CLASS_HUFFMAN_ONLY 2 478 +#define Z_CLASS_HUFFMAN_ONLY 2
478 + 479 +
479 #define zlib_version zlibVersion() 480 #define zlib_version zlibVersion()
480 /* for compatibility with versions < 1.0.2 */ 481 /* for compatibility with versions < 1.0.2 */
481 482
482 @@ -1744,6 +1749,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backwa rd compatibility */ 483 @@ -1587,6 +1592,13 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
483 ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); 484 ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
484 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 485 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
485 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 486 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
486 +# else 487 +# else
487 + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); 488 + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
488 + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); 489 + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
489 + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); 490 + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
490 + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); 491 + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
491 + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 492 + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
492 + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 493 + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
493 # endif 494 # endif
494 #else 495 #else
495 ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); 496 ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
496 --
497 2.7.4
498
OLDNEW
« no previous file with comments | « third_party/zlib/inftrees.c ('k') | third_party/zlib/mozzconf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698