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

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

Issue 10957038: net: separate SPDY cookies with "; " as the new RFC requires. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: g cl try Created 8 years, 3 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 | Annotate | Revision Log
« net/spdy/spdy_framer.cc ('K') | « third_party/zlib/deflate.c ('k') | no next file » | 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..02d1516 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,67 @@ 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)
227 + deflate_state *s; 227 + deflate_state *s;
228 + IPos start; 228 + IPos start;
229 + unsigned len; 229 + unsigned len;
230 +{ 230 +{
231 + unsigned hash = 5381; 231 + unsigned hash = 5381;
232 + Bytef *str = s->window + start; 232 + Bytef *str = s->window + start;
233 + unsigned i; 233 + unsigned i;
234 + IPos cookie_location; 234 + IPos cookie_location;
235 + 235 +
236 + if (len >= MAX_MATCH) 236 + if (len >= MAX_MATCH || len == 0)
237 + return 0; 237 + return 0;
238 + 238 +
239 + for (i = 0; i < len; i++) 239 + for (i = 0; i < len; i++)
240 + hash = ((hash << 5) + hash) + str[i]; 240 + hash = ((hash << 5) + hash) + str[i];
241 + 241 +
242 + hash &= Z_COOKIE_HASH_MASK; 242 + hash &= Z_COOKIE_HASH_MASK;
243 + cookie_location = s->cookie_locations[hash]; 243 + cookie_location = s->cookie_locations[hash];
244 + s->cookie_locations[hash] = start; 244 + s->cookie_locations[hash] = start;
245 + s->match_start = 0; 245 + s->match_start = 0;
246 + if (cookie_location && 246 + if (cookie_location &&
247 + (start - cookie_location) > len && 247 + (start - cookie_location) > len &&
248 + (start - cookie_location) < MAX_DIST(s) && 248 + (start - cookie_location) < MAX_DIST(s) &&
249 + len <= s->lookahead) { 249 + len <= s->lookahead) {
250 + for (i = 0; i < len; i++) { 250 + for (i = 0; i < len; i++) {
251 + if (s->window[start+i] != s->window[cookie_location+i] || 251 + if (s->window[start+i] != s->window[cookie_location+i] ||
252 + class_at(s, cookie_location+i) != 1) { 252 + class_at(s, cookie_location+i) != 1) {
253 + return 0; 253 + return 0;
254 + } 254 + }
255 + } 255 + }
256 + /* Check that we aren't matching a prefix of another cookie by ensuring
257 + * that the final byte is either a semicolon (which cannot appear in a
258 + * cookie value), or non-cookie data. */
259 + if (s->window[cookie_location+len-1] != ';' &&
260 + class_at(s, cookie_location+len) != 0) {
261 + return 0;
262 + }
256 + s->match_start = cookie_location; 263 + s->match_start = cookie_location;
257 + return len; 264 + return len;
258 + } 265 + }
259 + 266 +
260 + return 0; 267 + return 0;
261 +} 268 +}
262 + 269 +
263 + 270 +
264 #else /* FASTEST */ 271 #else /* FASTEST */
265 272
266 /* --------------------------------------------------------------------------- 273 /* ---------------------------------------------------------------------------
267 * Optimized version for FASTEST only 274 * Optimized version for FASTEST only
268 */ 275 */
269 -local uInt longest_match(s, cur_match) 276 -local uInt longest_match(s, cur_match)
270 +local uInt longest_match(s, cur_match, clas) 277 +local uInt longest_match(s, cur_match, clas)
271 deflate_state *s; 278 deflate_state *s;
272 IPos cur_match; /* current match */ 279 IPos cur_match; /* current match */
273 + int clas; 280 + int clas;
274 { 281 {
275 register Bytef *scan = s->window + s->strstart; /* current string */ 282 register Bytef *scan = s->window + s->strstart; /* current string */
276 register Bytef *match; /* matched string */ 283 register Bytef *match; /* matched string */
277 register int len; /* length of current match */ 284 register int len; /* length of current match */
278 register Bytef *strend = s->window + s->strstart + MAX_MATCH; 285 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
279 286
280 +#error "This code not patched" 287 +#error "This code not patched"
281 + 288 +
282 /* 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.
283 * It is easy to get rid of this optimization if necessary. 290 * It is easy to get rid of this optimization if necessary.
284 */ 291 */
285 @@ -1360,6 +1496,21 @@ local void fill_window(s) 292 @@ -1360,6 +1503,21 @@ local void fill_window(s)
286 */ 293 */
287 } while (--n); 294 } while (--n);
288 #endif 295 #endif
289 + 296 +
290 + for (n = 0; n < Z_COOKIE_HASH_SIZE; n++) { 297 + for (n = 0; n < Z_COOKIE_HASH_SIZE; n++) {
291 + if (s->cookie_locations[n] > wsize) { 298 + if (s->cookie_locations[n] > wsize) {
292 + s->cookie_locations[n] -= wsize; 299 + s->cookie_locations[n] -= wsize;
293 + } else { 300 + } else {
294 + s->cookie_locations[n] = 0; 301 + s->cookie_locations[n] = 0;
295 + } 302 + }
296 + } 303 + }
297 + 304 +
298 + if (s->class_bitmap) { 305 + if (s->class_bitmap) {
299 + zmemcpy(s->class_bitmap, s->class_bitmap + s->w_size/8, 306 + zmemcpy(s->class_bitmap, s->class_bitmap + s->w_size/8,
300 + s->w_size/8); 307 + s->w_size/8);
301 + 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);
302 + } 309 + }
303 + 310 +
304 more += wsize; 311 more += wsize;
305 } 312 }
306 if (s->strm->avail_in == 0) return; 313 if (s->strm->avail_in == 0) return;
307 @@ -1378,6 +1529,9 @@ local void fill_window(s) 314 @@ -1378,6 +1536,9 @@ local void fill_window(s)
308 Assert(more >= 2, "more < 2"); 315 Assert(more >= 2, "more < 2");
309 316
310 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);
311 + if (s->class_bitmap != NULL) { 318 + if (s->class_bitmap != NULL) {
312 + class_set(s, s->strstart + s->lookahead, n, s->strm->clas); 319 + class_set(s, s->strstart + s->lookahead, n, s->strm->clas);
313 + } 320 + }
314 s->lookahead += n; 321 s->lookahead += n;
315 322
316 /* Initialize the hash value now that we have some input: */ 323 /* Initialize the hash value now that we have some input: */
317 @@ -1459,9 +1613,10 @@ local void fill_window(s) 324 @@ -1459,9 +1620,10 @@ local void fill_window(s)
318 * NOTE: this function should be optimized to avoid extra copying from 325 * NOTE: this function should be optimized to avoid extra copying from
319 * window to pending_buf. 326 * window to pending_buf.
320 */ 327 */
321 -local block_state deflate_stored(s, flush) 328 -local block_state deflate_stored(s, flush)
322 +local block_state deflate_stored(s, flush, clas) 329 +local block_state deflate_stored(s, flush, clas)
323 deflate_state *s; 330 deflate_state *s;
324 int flush; 331 int flush;
325 + int clas; 332 + int clas;
326 { 333 {
327 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited 334 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
328 * 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:
329 @@ -1517,13 +1672,19 @@ local block_state deflate_stored(s, flush) 336 @@ -1517,13 +1679,19 @@ local block_state deflate_stored(s, flush)
330 * 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
331 * matches. It is used only for the fast compression options. 338 * matches. It is used only for the fast compression options.
332 */ 339 */
333 -local block_state deflate_fast(s, flush) 340 -local block_state deflate_fast(s, flush)
334 +local block_state deflate_fast(s, flush, clas) 341 +local block_state deflate_fast(s, flush, clas)
335 deflate_state *s; 342 deflate_state *s;
336 int flush; 343 int flush;
337 + int clas; 344 + int clas;
338 { 345 {
339 IPos hash_head; /* head of the hash chain */ 346 IPos hash_head; /* head of the hash chain */
340 int bflush; /* set if current block must be flushed */ 347 int bflush; /* set if current block must be flushed */
341 348
342 + if (clas != 0) { 349 + if (clas != 0) {
343 + /* We haven't patched this code for alternative class data. */ 350 + /* We haven't patched this code for alternative class data. */
344 + return Z_BUF_ERROR; 351 + return Z_BUF_ERROR;
345 + } 352 + }
346 + 353 +
347 for (;;) { 354 for (;;) {
348 /* Make sure that we always have enough lookahead, except 355 /* Make sure that we always have enough lookahead, except
349 * 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
350 @@ -1554,7 +1715,7 @@ local block_state deflate_fast(s, flush) 357 @@ -1554,7 +1722,7 @@ local block_state deflate_fast(s, flush)
351 * 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
352 * 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).
353 */ 360 */
354 - s->match_length = longest_match (s, hash_head); 361 - s->match_length = longest_match (s, hash_head);
355 + s->match_length = longest_match (s, hash_head, clas); 362 + s->match_length = longest_match (s, hash_head, clas);
356 /* longest_match() sets match_start */ 363 /* longest_match() sets match_start */
357 } 364 }
358 if (s->match_length >= MIN_MATCH) { 365 if (s->match_length >= MIN_MATCH) {
359 @@ -1613,12 +1774,25 @@ local block_state deflate_fast(s, flush) 366 @@ -1613,12 +1781,25 @@ local block_state deflate_fast(s, flush)
360 * 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
361 * no better match at the next window position. 368 * no better match at the next window position.
362 */ 369 */
363 -local block_state deflate_slow(s, flush) 370 -local block_state deflate_slow(s, flush)
364 +local block_state deflate_slow(s, flush, clas) 371 +local block_state deflate_slow(s, flush, clas)
365 deflate_state *s; 372 deflate_state *s;
366 int flush; 373 int flush;
367 + int clas; 374 + int clas;
368 { 375 {
369 IPos hash_head; /* head of hash chain */ 376 IPos hash_head; /* head of hash chain */
370 int bflush; /* set if current block must be flushed */ 377 int bflush; /* set if current block must be flushed */
371 + uInt input_length ; 378 + uInt input_length ;
372 + int first = 1; /* first says whether this is the first iteration 379 + int first = 1; /* first says whether this is the first iteration
373 + of the loop, below. */ 380 + of the loop, below. */
374 + 381 +
375 + if (clas == Z_CLASS_COOKIE) { 382 + if (clas == Z_CLASS_COOKIE) {
376 + if (s->lookahead) { 383 + if (s->lookahead) {
377 + /* Alternative class data must always be presented at the beginning 384 + /* Alternative class data must always be presented at the beginning
378 + * of a block. */ 385 + * of a block. */
379 + return Z_BUF_ERROR; 386 + return Z_BUF_ERROR;
380 + } 387 + }
381 + input_length = s->strm->avail_in; 388 + input_length = s->strm->avail_in;
382 + } 389 + }
383 390
384 /* Process the input block. */ 391 /* Process the input block. */
385 for (;;) { 392 for (;;) {
386 @@ -1648,13 +1822,18 @@ local block_state deflate_slow(s, flush) 393 @@ -1648,13 +1829,18 @@ local block_state deflate_slow(s, flush)
387 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;
388 s->match_length = MIN_MATCH-1; 395 s->match_length = MIN_MATCH-1;
389 396
390 - if (hash_head != NIL && s->prev_length < s->max_lazy_match && 397 - if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
391 - s->strstart - hash_head <= MAX_DIST(s)) { 398 - s->strstart - hash_head <= MAX_DIST(s)) {
392 + if (clas == Z_CLASS_COOKIE && first) { 399 + if (clas == Z_CLASS_COOKIE && first) {
393 + s->match_length = cookie_match(s, s->strstart, input_length); 400 + s->match_length = cookie_match(s, s->strstart, input_length);
394 + } else if (clas == Z_CLASS_STANDARD && 401 + } else if (clas == Z_CLASS_STANDARD &&
395 + hash_head != NIL && 402 + hash_head != NIL &&
396 + s->prev_length < s->max_lazy_match && 403 + s->prev_length < s->max_lazy_match &&
397 + s->strstart - hash_head <= MAX_DIST(s)) { 404 + s->strstart - hash_head <= MAX_DIST(s)) {
398 /* To simplify the code, we prevent matches with the string 405 /* To simplify the code, we prevent matches with the string
399 * 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
400 * 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).
401 */ 408 */
402 - s->match_length = longest_match (s, hash_head); 409 - s->match_length = longest_match (s, hash_head);
403 + s->match_length = longest_match (s, hash_head, clas); 410 + s->match_length = longest_match (s, hash_head, clas);
404 + 411 +
405 /* longest_match() sets match_start */ 412 /* longest_match() sets match_start */
406 413
407 if (s->match_length <= 5 && (s->strategy == Z_FILTERED 414 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
408 @@ -1673,7 +1852,22 @@ local block_state deflate_slow(s, flush) 415 @@ -1673,7 +1859,20 @@ local block_state deflate_slow(s, flush)
409 /* 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
410 * match is not better, output the previous match: 417 * match is not better, output the previous match:
411 */ 418 */
412 - 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) {
413 + first = 0; 420 + first = 0;
414 + 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 &&
415 + /* 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
416 + * we won't match Z_CLASS_HUFFMAN_ONLY data at all. */ 423 + * we won't match Z_CLASS_HUFFMAN_ONLY data at all. */
417 + (clas == Z_CLASS_STANDARD || (clas == Z_CLASS_COOKIE && 424 + (clas == Z_CLASS_STANDARD || (clas == Z_CLASS_COOKIE &&
418 + s->prev_length == input_length && 425 + s->prev_length == input_length &&
419 + s->prev_match > 0 && 426 + s->prev_match > 0 &&
420 + /* We require that a Z_CLASS_COOKIE match be 427 + /* We require that a Z_CLASS_COOKIE match be
421 + * preceded by either a semicolon (which cannot be 428 + * preceded by either a semicolon (which cannot be
422 + * part of a cookie), or non-cookie data. This is 429 + * part of a cookie), or non-cookie data. This is
423 + * to prevent 430 + * to prevent a cookie from being a suffix of
424 + * a cookie from being a prefix of another. 431 + * another. */
425 + * spdy_framer.cc ensures that cookies are always
426 + * terminated by a semicolon. */
427 + (class_at(s, s->prev_match-1) == Z_CLASS_STANDARD | | 432 + (class_at(s, s->prev_match-1) == Z_CLASS_STANDARD | |
428 + *(s->window + s->prev_match-1) == ';')))) { 433 + *(s->window + s->prev_match-1) == ';')))) {
429 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; 434 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
430 /* Do not insert strings in hash table beyond this. */ 435 /* Do not insert strings in hash table beyond this. */
431 436
432 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
433 index cbf0d1e..83b4602 100644 438 index cbf0d1e..2fe6fd6 100644
434 --- a/third_party/zlib/deflate.h 439 --- a/third_party/zlib/deflate.h
435 +++ b/third_party/zlib/deflate.h 440 +++ b/third_party/zlib/deflate.h
436 @@ -91,6 +91,9 @@ typedef unsigned IPos; 441 @@ -91,6 +91,9 @@ typedef unsigned IPos;
437 * 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.
438 */ 443 */
439 444
440 +#define Z_COOKIE_HASH_SIZE 64 445 +#define Z_COOKIE_HASH_SIZE 256
441 +#define Z_COOKIE_HASH_MASK (Z_COOKIE_HASH_SIZE-1) 446 +#define Z_COOKIE_HASH_MASK (Z_COOKIE_HASH_SIZE-1)
442 + 447 +
443 typedef struct internal_state { 448 typedef struct internal_state {
444 z_streamp strm; /* pointer back to this zlib stream */ 449 z_streamp strm; /* pointer back to this zlib stream */
445 int status; /* as the name implies */ 450 int status; /* as the name implies */
446 @@ -139,6 +142,8 @@ typedef struct internal_state { 451 @@ -139,6 +142,8 @@ typedef struct internal_state {
447 uInt hash_mask; /* hash_size-1 */ 452 uInt hash_mask; /* hash_size-1 */
448 453
449 uInt hash_shift; 454 uInt hash_shift;
450 + Bytef *class_bitmap; /* bitmap of class for each byte in window */ 455 + Bytef *class_bitmap; /* bitmap of class for each byte in window */
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 +# else 487 +# else
483 + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); 488 + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
484 + 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));
485 + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); 490 + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
486 + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); 491 + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
487 + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 492 + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
488 + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 493 + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
489 # endif 494 # endif
490 #else 495 #else
491 ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); 496 ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
OLDNEW
« net/spdy/spdy_framer.cc ('K') | « third_party/zlib/deflate.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698