| OLD | NEW |
| 1 /* deflate.c -- compress data using the deflation algorithm | 1 /* deflate.c -- compress data using the deflation algorithm |
| 2 * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler | 2 * Copyright (C) 1995-2010 Jean-loup Gailly and 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 |
| 6 /* | 6 /* |
| 7 * ALGORITHM | 7 * ALGORITHM |
| 8 * | 8 * |
| 9 * The "deflation" process depends on being able to identify portions | 9 * The "deflation" process depends on being able to identify portions |
| 10 * of the input text which are identical to earlier input (within a | 10 * of the input text which are identical to earlier input (within a |
| (...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 local uInt cookie_match(s, start, len) | 1302 local uInt cookie_match(s, start, len) |
| 1303 deflate_state *s; | 1303 deflate_state *s; |
| 1304 IPos start; | 1304 IPos start; |
| 1305 unsigned len; | 1305 unsigned len; |
| 1306 { | 1306 { |
| 1307 unsigned hash = 5381; | 1307 unsigned hash = 5381; |
| 1308 Bytef *str = s->window + start; | 1308 Bytef *str = s->window + start; |
| 1309 unsigned i; | 1309 unsigned i; |
| 1310 IPos cookie_location; | 1310 IPos cookie_location; |
| 1311 | 1311 |
| 1312 if (len >= MAX_MATCH) | 1312 if (len >= MAX_MATCH || len == 0) |
| 1313 return 0; | 1313 return 0; |
| 1314 | 1314 |
| 1315 for (i = 0; i < len; i++) | 1315 for (i = 0; i < len; i++) |
| 1316 hash = ((hash << 5) + hash) + str[i]; | 1316 hash = ((hash << 5) + hash) + str[i]; |
| 1317 | 1317 |
| 1318 hash &= Z_COOKIE_HASH_MASK; | 1318 hash &= Z_COOKIE_HASH_MASK; |
| 1319 cookie_location = s->cookie_locations[hash]; | 1319 cookie_location = s->cookie_locations[hash]; |
| 1320 s->cookie_locations[hash] = start; | 1320 s->cookie_locations[hash] = start; |
| 1321 s->match_start = 0; | 1321 s->match_start = 0; |
| 1322 if (cookie_location && | 1322 if (cookie_location && |
| 1323 (start - cookie_location) > len && | 1323 (start - cookie_location) > len && |
| 1324 (start - cookie_location) < MAX_DIST(s) && | 1324 (start - cookie_location) < MAX_DIST(s) && |
| 1325 len <= s->lookahead) { | 1325 len <= s->lookahead) { |
| 1326 for (i = 0; i < len; i++) { | 1326 for (i = 0; i < len; i++) { |
| 1327 if (s->window[start+i] != s->window[cookie_location+i] || | 1327 if (s->window[start+i] != s->window[cookie_location+i] || |
| 1328 class_at(s, cookie_location+i) != 1) { | 1328 class_at(s, cookie_location+i) != 1) { |
| 1329 return 0; | 1329 return 0; |
| 1330 } | 1330 } |
| 1331 } | 1331 } |
| 1332 /* Check that we aren't matching a prefix of another cookie by ensuring |
| 1333 * that the final byte is either a semicolon (which cannot appear in a |
| 1334 * cookie value), or the match is followed by non-cookie data. */ |
| 1335 if (s->window[cookie_location+len-1] != ';' && |
| 1336 class_at(s, cookie_location+len) != 0) { |
| 1337 return 0; |
| 1338 } |
| 1332 s->match_start = cookie_location; | 1339 s->match_start = cookie_location; |
| 1333 return len; | 1340 return len; |
| 1334 } | 1341 } |
| 1335 | 1342 |
| 1336 return 0; | 1343 return 0; |
| 1337 } | 1344 } |
| 1338 | 1345 |
| 1339 | 1346 |
| 1340 #else /* FASTEST */ | 1347 #else /* FASTEST */ |
| 1341 | 1348 |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1855 first = 0; | 1862 first = 0; |
| 1856 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length && | 1863 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length && |
| 1857 /* We will only accept an exact match for Z_CLASS_COOKIE data and | 1864 /* We will only accept an exact match for Z_CLASS_COOKIE data and |
| 1858 * we won't match Z_CLASS_HUFFMAN_ONLY data at all. */ | 1865 * we won't match Z_CLASS_HUFFMAN_ONLY data at all. */ |
| 1859 (clas == Z_CLASS_STANDARD || (clas == Z_CLASS_COOKIE && | 1866 (clas == Z_CLASS_STANDARD || (clas == Z_CLASS_COOKIE && |
| 1860 s->prev_length == input_length && | 1867 s->prev_length == input_length && |
| 1861 s->prev_match > 0 && | 1868 s->prev_match > 0 && |
| 1862 /* We require that a Z_CLASS_COOKIE match be | 1869 /* We require that a Z_CLASS_COOKIE match be |
| 1863 * preceded by either a semicolon (which cannot be | 1870 * preceded by either a semicolon (which cannot be |
| 1864 * part of a cookie), or non-cookie data. This is | 1871 * part of a cookie), or non-cookie data. This is |
| 1865 * to prevent | 1872 * to prevent a cookie from being a suffix of |
| 1866 * a cookie from being a prefix of another. | 1873 * another. */ |
| 1867 * spdy_framer.cc ensures that cookies are always | |
| 1868 * terminated by a semicolon. */ | |
| 1869 (class_at(s, s->prev_match-1) == Z_CLASS_STANDARD || | 1874 (class_at(s, s->prev_match-1) == Z_CLASS_STANDARD || |
| 1870 *(s->window + s->prev_match-1) == ';')))) { | 1875 *(s->window + s->prev_match-1) == ';')))) { |
| 1871 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; | 1876 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; |
| 1872 /* Do not insert strings in hash table beyond this. */ | 1877 /* Do not insert strings in hash table beyond this. */ |
| 1873 | 1878 |
| 1874 check_match(s, s->strstart-1, s->prev_match, s->prev_length); | 1879 check_match(s, s->strstart-1, s->prev_match, s->prev_length); |
| 1875 | 1880 |
| 1876 _tr_tally_dist(s, s->strstart -1 - s->prev_match, | 1881 _tr_tally_dist(s, s->strstart -1 - s->prev_match, |
| 1877 s->prev_length - MIN_MATCH, bflush); | 1882 s->prev_length - MIN_MATCH, bflush); |
| 1878 | 1883 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2019 s->match_length = 0; | 2024 s->match_length = 0; |
| 2020 Tracevv((stderr,"%c", s->window[s->strstart])); | 2025 Tracevv((stderr,"%c", s->window[s->strstart])); |
| 2021 _tr_tally_lit (s, s->window[s->strstart], bflush); | 2026 _tr_tally_lit (s, s->window[s->strstart], bflush); |
| 2022 s->lookahead--; | 2027 s->lookahead--; |
| 2023 s->strstart++; | 2028 s->strstart++; |
| 2024 if (bflush) FLUSH_BLOCK(s, 0); | 2029 if (bflush) FLUSH_BLOCK(s, 0); |
| 2025 } | 2030 } |
| 2026 FLUSH_BLOCK(s, flush == Z_FINISH); | 2031 FLUSH_BLOCK(s, flush == Z_FINISH); |
| 2027 return flush == Z_FINISH ? finish_done : block_done; | 2032 return flush == Z_FINISH ? finish_done : block_done; |
| 2028 } | 2033 } |
| OLD | NEW |