@@ -229,6 +229,8 @@ int ZEXPORT deflateInit(strm, level)
229
229
/* To do: ignore strm->next_in if we use it as window */
230
230
}
231
231
232
+ #define WINDOW_PADDING 8
233
+
232
234
/* ========================================================================= */
233
235
int ZEXPORT deflateInit2 (strm , level , method , windowBits , memLevel , strategy )
234
236
z_streamp strm ;
@@ -238,7 +240,6 @@ int ZEXPORT deflateInit2(strm, level, method, windowBits, memLevel, strategy)
238
240
int memLevel ;
239
241
int strategy ;
240
242
{
241
- unsigned window_padding = 8 ;
242
243
deflate_state * s ;
243
244
int wrap = 1 ;
244
245
@@ -325,12 +326,12 @@ int ZEXPORT deflateInit2(strm, level, method, windowBits, memLevel, strategy)
325
326
s -> hash_shift = ((s -> hash_bits + MIN_MATCH - 1 ) / MIN_MATCH );
326
327
327
328
s -> window = (Bytef * ) ZALLOC (strm ,
328
- s -> w_size + window_padding ,
329
+ s -> w_size + WINDOW_PADDING ,
329
330
2 * sizeof (Byte ));
330
331
/* Avoid use of unitialized values in the window, see crbug.com/1137613 and
331
332
* crbug.com/1144420 */
332
333
if (s -> window ) { /* [jart] fix regression in malloc failure checking */
333
- zmemzero (s -> window , (s -> w_size + window_padding ) * (2 * sizeof (Byte )));
334
+ zmemzero (s -> window , (s -> w_size + WINDOW_PADDING ) * (2 * sizeof (Byte )));
334
335
}
335
336
s -> prev = (Posf * ) ZALLOC (strm , s -> w_size , sizeof (Pos ));
336
337
/* Avoid use of uninitialized value, see:
@@ -770,6 +771,12 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
770
771
wraplen = 6 ;
771
772
}
772
773
774
+ /* With Chromium's hashing, s->hash_bits may not correspond to the
775
+ memLevel, making the computations below incorrect. Return the
776
+ conservative bound. */
777
+ if (s -> chromium_zlib_hash )
778
+ return (fixedlen > storelen ? fixedlen : storelen ) + wraplen ;
779
+
773
780
/* if not default parameters, return one of the conservative bounds */
774
781
if (s -> w_bits != 15 || s -> hash_bits != 8 + 7 )
775
782
return (s -> w_bits <= s -> hash_bits ? fixedlen : storelen ) + wraplen ;
@@ -1199,7 +1206,9 @@ int ZEXPORT deflateCopy(dest, source)
1199
1206
zmemcpy ((voidpf )ds , (voidpf )ss , sizeof (deflate_state ));
1200
1207
ds -> strm = dest ;
1201
1208
1202
- ds -> window = (Bytef * ) ZALLOC (dest , ds -> w_size , 2 * sizeof (Byte ));
1209
+ ds -> window = (Bytef * ) ZALLOC (dest ,
1210
+ ds -> w_size + WINDOW_PADDING ,
1211
+ 2 * sizeof (Byte ));
1203
1212
ds -> prev = (Posf * ) ZALLOC (dest , ds -> w_size , sizeof (Pos ));
1204
1213
ds -> head = (Posf * ) ZALLOC (dest , ds -> hash_size , sizeof (Pos ));
1205
1214
ds -> pending_buf = (uchf * ) ZALLOC (dest , ds -> lit_bufsize , 4 );
@@ -1210,7 +1219,8 @@ int ZEXPORT deflateCopy(dest, source)
1210
1219
return Z_MEM_ERROR ;
1211
1220
}
1212
1221
/* following zmemcpy do not work for 16-bit MSDOS */
1213
- zmemcpy (ds -> window , ss -> window , ds -> w_size * 2 * sizeof (Byte ));
1222
+ zmemcpy (ds -> window , ss -> window ,
1223
+ (ds -> w_size + WINDOW_PADDING ) * 2 * sizeof (Byte ));
1214
1224
zmemcpy ((voidpf )ds -> prev , (voidpf )ss -> prev , ds -> w_size * sizeof (Pos ));
1215
1225
zmemcpy ((voidpf )ds -> head , (voidpf )ss -> head , ds -> hash_size * sizeof (Pos ));
1216
1226
zmemcpy (ds -> pending_buf , ss -> pending_buf , (uInt )ds -> pending_buf_size );
0 commit comments