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

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

Issue 2084863002: 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 5c4022f..88b2ec0 100644 2 index 6969577..7c95b30 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 @@ -281,6 +282,9 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, m emLevel, strategy, 37 @@ -293,6 +294,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 @@ -367,6 +371,8 @@ int ZEXPORT deflateReset (strm) 47 @@ -406,6 +410,8 @@ int ZEXPORT deflateResetKeep (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 @@ -817,9 +823,26 @@ int ZEXPORT deflate (strm, flush) 56 @@ -900,9 +906,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 @@ -915,6 +938,7 @@ int ZEXPORT deflateEnd (strm) 86 @@ -999,6 +1022,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 @@ -1046,6 +1070,57 @@ local void lm_init (s) 94 @@ -1131,6 +1155,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 @@ -1060,9 +1135,10 @@ local void lm_init (s) 152 @@ -1145,9 +1220,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 @@ -1110,6 +1186,9 @@ local uInt longest_match(s, cur_match) 164 @@ -1195,6 +1271,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 @@ -1152,6 +1231,8 @@ local uInt longest_match(s, cur_match) 174 @@ -1237,6 +1316,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 @@ -1168,15 +1249,23 @@ local uInt longest_match(s, cur_match) 183 @@ -1253,15 +1334,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 @@ -1204,20 +1293,74 @@ local uInt longest_match(s, cur_match) 216 @@ -1289,20 +1378,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 @@ -1360,6 +1503,21 @@ local void fill_window(s) 292 @@ -1447,6 +1590,20 @@ local void fill_window(s)
293 */ 293 */
294 } while (--n); 294 } while (--n);
295 #endif 295 #endif
296 +
297 + for (n = 0; n < Z_COOKIE_HASH_SIZE; n++) { 296 + for (n = 0; n < Z_COOKIE_HASH_SIZE; n++) {
298 + if (s->cookie_locations[n] > wsize) { 297 + if (s->cookie_locations[n] > wsize) {
299 + s->cookie_locations[n] -= wsize; 298 + s->cookie_locations[n] -= wsize;
300 + } else { 299 + } else {
301 + s->cookie_locations[n] = 0; 300 + s->cookie_locations[n] = 0;
302 + } 301 + }
303 + } 302 + }
304 + 303 +
305 + if (s->class_bitmap) { 304 + if (s->class_bitmap) {
306 + zmemcpy(s->class_bitmap, s->class_bitmap + s->w_size/8, 305 + zmemcpy(s->class_bitmap, s->class_bitmap + s->w_size/8,
307 + s->w_size/8); 306 + s->w_size/8);
308 + zmemzero(s->class_bitmap + s->w_size/8, s->w_size/8); 307 + zmemzero(s->class_bitmap + s->w_size/8, s->w_size/8);
309 + } 308 + }
310 + 309 +
311 more += wsize; 310 more += wsize;
312 } 311 }
313 if (s->strm->avail_in == 0) return; 312 if (s->strm->avail_in == 0) break;
314 @@ -1378,6 +1536,9 @@ local void fill_window(s) 313 @@ -1465,6 +1622,9 @@ local void fill_window(s)
315 Assert(more >= 2, "more < 2"); 314 Assert(more >= 2, "more < 2");
316 315
317 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); 316 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
318 + if (s->class_bitmap != NULL) { 317 + if (s->class_bitmap != NULL) {
319 + class_set(s, s->strstart + s->lookahead, n, s->strm->clas); 318 + class_set(s, s->strstart + s->lookahead, n, s->strm->clas);
320 + } 319 + }
321 s->lookahead += n; 320 s->lookahead += n;
322 321
323 /* Initialize the hash value now that we have some input: */ 322 /* Initialize the hash value now that we have some input: */
324 @@ -1459,9 +1620,10 @@ local void fill_window(s) 323 @@ -1561,9 +1721,10 @@ local void fill_window(s)
325 * NOTE: this function should be optimized to avoid extra copying from 324 * NOTE: this function should be optimized to avoid extra copying from
326 * window to pending_buf. 325 * window to pending_buf.
327 */ 326 */
328 -local block_state deflate_stored(s, flush) 327 -local block_state deflate_stored(s, flush)
329 +local block_state deflate_stored(s, flush, clas) 328 +local block_state deflate_stored(s, flush, clas)
330 deflate_state *s; 329 deflate_state *s;
331 int flush; 330 int flush;
332 + int clas; 331 + int clas;
333 { 332 {
334 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited 333 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
335 * to pending_buf_size, and each stored block has a 5 byte header: 334 * to pending_buf_size, and each stored block has a 5 byte header:
336 @@ -1517,13 +1679,19 @@ local block_state deflate_stored(s, flush) 335 @@ -1625,13 +1786,19 @@ local block_state deflate_stored(s, flush)
337 * new strings in the dictionary only for unmatched strings or for short 336 * new strings in the dictionary only for unmatched strings or for short
338 * matches. It is used only for the fast compression options. 337 * matches. It is used only for the fast compression options.
339 */ 338 */
340 -local block_state deflate_fast(s, flush) 339 -local block_state deflate_fast(s, flush)
341 +local block_state deflate_fast(s, flush, clas) 340 +local block_state deflate_fast(s, flush, clas)
342 deflate_state *s; 341 deflate_state *s;
343 int flush; 342 int flush;
344 + int clas; 343 + int clas;
345 { 344 {
346 IPos hash_head; /* head of the hash chain */ 345 IPos hash_head; /* head of the hash chain */
347 int bflush; /* set if current block must be flushed */ 346 int bflush; /* set if current block must be flushed */
348 347
349 + if (clas != 0) { 348 + if (clas != 0) {
350 + /* We haven't patched this code for alternative class data. */ 349 + /* We haven't patched this code for alternative class data. */
351 + return Z_BUF_ERROR; 350 + return Z_BUF_ERROR;
352 + } 351 + }
353 + 352 +
354 for (;;) { 353 for (;;) {
355 /* Make sure that we always have enough lookahead, except 354 /* Make sure that we always have enough lookahead, except
356 * at the end of the input file. We need MAX_MATCH bytes 355 * at the end of the input file. We need MAX_MATCH bytes
357 @@ -1554,7 +1722,7 @@ local block_state deflate_fast(s, flush) 356 @@ -1662,7 +1829,7 @@ local block_state deflate_fast(s, flush)
358 * of window index 0 (in particular we have to avoid a match 357 * of window index 0 (in particular we have to avoid a match
359 * of the string with itself at the start of the input file). 358 * of the string with itself at the start of the input file).
360 */ 359 */
361 - s->match_length = longest_match (s, hash_head); 360 - s->match_length = longest_match (s, hash_head);
362 + s->match_length = longest_match (s, hash_head, clas); 361 + s->match_length = longest_match (s, hash_head, clas);
363 /* longest_match() sets match_start */ 362 /* longest_match() sets match_start */
364 } 363 }
365 if (s->match_length >= MIN_MATCH) { 364 if (s->match_length >= MIN_MATCH) {
366 @@ -1613,12 +1781,25 @@ local block_state deflate_fast(s, flush) 365 @@ -1727,12 +1894,25 @@ local block_state deflate_fast(s, flush)
367 * evaluation for matches: a match is finally adopted only if there is 366 * evaluation for matches: a match is finally adopted only if there is
368 * no better match at the next window position. 367 * no better match at the next window position.
369 */ 368 */
370 -local block_state deflate_slow(s, flush) 369 -local block_state deflate_slow(s, flush)
371 +local block_state deflate_slow(s, flush, clas) 370 +local block_state deflate_slow(s, flush, clas)
372 deflate_state *s; 371 deflate_state *s;
373 int flush; 372 int flush;
374 + int clas; 373 + int clas;
375 { 374 {
376 IPos hash_head; /* head of hash chain */ 375 IPos hash_head; /* head of hash chain */
377 int bflush; /* set if current block must be flushed */ 376 int bflush; /* set if current block must be flushed */
378 + uInt input_length ; 377 + uInt input_length ;
379 + int first = 1; /* first says whether this is the first iteration 378 + int first = 1; /* first says whether this is the first iteration
380 + of the loop, below. */ 379 + of the loop, below. */
381 + 380 +
382 + if (clas == Z_CLASS_COOKIE) { 381 + if (clas == Z_CLASS_COOKIE) {
383 + if (s->lookahead) { 382 + if (s->lookahead) {
384 + /* Alternative class data must always be presented at the beginning 383 + /* Alternative class data must always be presented at the beginning
385 + * of a block. */ 384 + * of a block. */
386 + return Z_BUF_ERROR; 385 + return Z_BUF_ERROR;
387 + } 386 + }
388 + input_length = s->strm->avail_in; 387 + input_length = s->strm->avail_in;
389 + } 388 + }
390 389
391 /* Process the input block. */ 390 /* Process the input block. */
392 for (;;) { 391 for (;;) {
393 @@ -1648,13 +1829,18 @@ local block_state deflate_slow(s, flush) 392 @@ -1762,13 +1942,18 @@ local block_state deflate_slow(s, flush)
394 s->prev_length = s->match_length, s->prev_match = s->match_start; 393 s->prev_length = s->match_length, s->prev_match = s->match_start;
395 s->match_length = MIN_MATCH-1; 394 s->match_length = MIN_MATCH-1;
396 395
397 - if (hash_head != NIL && s->prev_length < s->max_lazy_match && 396 - if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
398 - s->strstart - hash_head <= MAX_DIST(s)) { 397 - s->strstart - hash_head <= MAX_DIST(s)) {
399 + if (clas == Z_CLASS_COOKIE && first) { 398 + if (clas == Z_CLASS_COOKIE && first) {
400 + s->match_length = cookie_match(s, s->strstart, input_length); 399 + s->match_length = cookie_match(s, s->strstart, input_length);
401 + } else if (clas == Z_CLASS_STANDARD && 400 + } else if (clas == Z_CLASS_STANDARD &&
402 + hash_head != NIL && 401 + hash_head != NIL &&
403 + s->prev_length < s->max_lazy_match && 402 + s->prev_length < s->max_lazy_match &&
404 + s->strstart - hash_head <= MAX_DIST(s)) { 403 + s->strstart - hash_head <= MAX_DIST(s)) {
405 /* To simplify the code, we prevent matches with the string 404 /* To simplify the code, we prevent matches with the string
406 * of window index 0 (in particular we have to avoid a match 405 * of window index 0 (in particular we have to avoid a match
407 * of the string with itself at the start of the input file). 406 * of the string with itself at the start of the input file).
408 */ 407 */
409 - s->match_length = longest_match (s, hash_head); 408 - s->match_length = longest_match (s, hash_head);
410 + s->match_length = longest_match (s, hash_head, clas); 409 + s->match_length = longest_match (s, hash_head, clas);
411 + 410 +
412 /* longest_match() sets match_start */ 411 /* longest_match() sets match_start */
413 412
414 if (s->match_length <= 5 && (s->strategy == Z_FILTERED 413 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
415 @@ -1673,7 +1859,20 @@ local block_state deflate_slow(s, flush) 414 @@ -1787,7 +1972,20 @@ local block_state deflate_slow(s, flush)
416 /* If there was a match at the previous step and the current 415 /* If there was a match at the previous step and the current
417 * match is not better, output the previous match: 416 * match is not better, output the previous match:
418 */ 417 */
419 - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { 418 - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
420 + first = 0; 419 + first = 0;
421 + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length && 420 + if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length &&
422 + /* We will only accept an exact match for Z_CLASS_COOKIE data and 421 + /* We will only accept an exact match for Z_CLASS_COOKIE data and
423 + * we won't match Z_CLASS_HUFFMAN_ONLY data at all. */ 422 + * we won't match Z_CLASS_HUFFMAN_ONLY data at all. */
424 + (clas == Z_CLASS_STANDARD || (clas == Z_CLASS_COOKIE && 423 + (clas == Z_CLASS_STANDARD || (clas == Z_CLASS_COOKIE &&
425 + s->prev_length == input_length && 424 + s->prev_length == input_length &&
426 + s->prev_match > 0 && 425 + s->prev_match > 0 &&
427 + /* We require that a Z_CLASS_COOKIE match be 426 + /* We require that a Z_CLASS_COOKIE match be
428 + * preceded by either a semicolon (which cannot be 427 + * preceded by either a semicolon (which cannot be
429 + * part of a cookie), or non-cookie data. This is 428 + * part of a cookie), or non-cookie data. This is
430 + * to prevent a cookie from being a suffix of 429 + * to prevent a cookie from being a suffix of
431 + * another. */ 430 + * another. */
432 + (class_at(s, s->prev_match-1) == Z_CLASS_STANDARD | | 431 + (class_at(s, s->prev_match-1) == Z_CLASS_STANDARD | |
433 + *(s->window + s->prev_match-1) == ';')))) { 432 + *(s->window + s->prev_match-1) == ';')))) {
434 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; 433 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
435 /* Do not insert strings in hash table beyond this. */ 434 /* Do not insert strings in hash table beyond this. */
436 435
437 diff --git a/third_party/zlib/deflate.h b/third_party/zlib/deflate.h 436 diff --git a/third_party/zlib/deflate.h b/third_party/zlib/deflate.h
438 index cbf0d1e..2fe6fd6 100644 437 index ce0299e..c795034 100644
439 --- a/third_party/zlib/deflate.h 438 --- a/third_party/zlib/deflate.h
440 +++ b/third_party/zlib/deflate.h 439 +++ b/third_party/zlib/deflate.h
441 @@ -91,6 +91,9 @@ typedef unsigned IPos; 440 @@ -94,6 +94,9 @@ typedef unsigned IPos;
442 * save space in the various tables. IPos is used only for parameter passing. 441 * save space in the various tables. IPos is used only for parameter passing.
443 */ 442 */
444 443
445 +#define Z_COOKIE_HASH_SIZE 256 444 +#define Z_COOKIE_HASH_SIZE 256
446 +#define Z_COOKIE_HASH_MASK (Z_COOKIE_HASH_SIZE-1) 445 +#define Z_COOKIE_HASH_MASK (Z_COOKIE_HASH_SIZE-1)
447 + 446 +
448 typedef struct internal_state { 447 typedef struct internal_state {
449 z_streamp strm; /* pointer back to this zlib stream */ 448 z_streamp strm; /* pointer back to this zlib stream */
450 int status; /* as the name implies */ 449 int status; /* as the name implies */
451 @@ -139,6 +142,8 @@ typedef struct internal_state { 450 @@ -142,6 +145,8 @@ typedef struct internal_state {
452 uInt hash_mask; /* hash_size-1 */ 451 uInt hash_mask; /* hash_size-1 */
453 452
454 uInt hash_shift; 453 uInt hash_shift;
455 + Bytef *class_bitmap; /* bitmap of class for each byte in window */ 454 + Bytef *class_bitmap; /* bitmap of class for each byte in window */
456 + IPos cookie_locations[Z_COOKIE_HASH_SIZE]; 455 + IPos cookie_locations[Z_COOKIE_HASH_SIZE];
457 /* Number of bits by which ins_h must be shifted at each input 456 /* Number of bits by which ins_h must be shifted at each input
458 * step. It must be such that after MIN_MATCH steps, the oldest 457 * step. It must be such that after MIN_MATCH steps, the oldest
459 * byte no longer takes part in the hash key, that is: 458 * byte no longer takes part in the hash key, that is:
460 diff --git a/third_party/zlib/zlib.h b/third_party/zlib/zlib.h 459 diff --git a/third_party/zlib/zlib.h b/third_party/zlib/zlib.h
461 index 4d54af9..da7e971 100644 460 index 36c73af..5544c88 100644
462 --- a/third_party/zlib/zlib.h 461 --- a/third_party/zlib/zlib.h
463 +++ b/third_party/zlib/zlib.h 462 +++ b/third_party/zlib/zlib.h
464 @@ -101,6 +101,7 @@ typedef struct z_stream_s { 463 @@ -101,6 +101,7 @@ typedef struct z_stream_s {
465 int data_type; /* best guess about the data type: binary or text */ 464 int data_type; /* best guess about the data type: binary or text */
466 uLong adler; /* adler32 value of the uncompressed data */ 465 uLong adler; /* adler32 value of the uncompressed data */
467 uLong reserved; /* reserved for future use */ 466 uLong reserved; /* reserved for future use */
468 + int clas; 467 + int clas;
469 } z_stream; 468 } z_stream;
470 469
471 typedef z_stream FAR *z_streamp; 470 typedef z_stream FAR *z_streamp;
472 @@ -207,6 +208,10 @@ typedef gz_header FAR *gz_headerp; 471 @@ -207,6 +208,10 @@ typedef gz_header FAR *gz_headerp;
473 472
474 #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 473 #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
475 474
476 +#define Z_CLASS_STANDARD 0 475 +#define Z_CLASS_STANDARD 0
477 +#define Z_CLASS_COOKIE 1 476 +#define Z_CLASS_COOKIE 1
478 +#define Z_CLASS_HUFFMAN_ONLY 2 477 +#define Z_CLASS_HUFFMAN_ONLY 2
479 + 478 +
480 #define zlib_version zlibVersion() 479 #define zlib_version zlibVersion()
481 /* for compatibility with versions < 1.0.2 */ 480 /* for compatibility with versions < 1.0.2 */
482 481
483 @@ -1587,6 +1592,13 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 482 @@ -1744,6 +1749,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backwa rd compatibility */
484 ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); 483 ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
485 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 484 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
486 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 485 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
487 +# else 486 +# else
488 + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); 487 + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
489 + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); 488 + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
490 + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); 489 + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
491 + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); 490 + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
492 + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 491 + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
493 + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 492 + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
494 # endif 493 # endif
495 #else 494 #else
496 ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); 495 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