[zlib] Make internal window allocation consistent.
The default internal window memory allocation logic
creates a 32K + CHUNKCOPY_CHUNK_SIZE bytes large
buffer; however, the inflateCopy() function that is
supposed to copy a source stream to a destination
stream allocates just a 32K buffer, so a smaller
buffer. The rest of the optimized logic, however,
assumes that the window is 32K + CHUNKCOPY_CHUNK_SIZE
when calling inflate_fast_chunk_. That entry
assumption is actually specified in inffast_chunk.c
on lines 35:36.
Bug: b/292062232
Change-Id: I94686e745428162546f954b95fb424f315a71d76
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4876445
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: Hans Wennborg <hans@chromium.org>
Commit-Queue: Filip Perich <perich@google.com>
Cr-Commit-Position: refs/heads/main@{#1199363}
NOKEYCHECK=True
GitOrigin-RevId: 8cd2a60036c5f0837e4d03848eb599393a33a132
diff --git a/contrib/optimizations/inflate.c b/contrib/optimizations/inflate.c
index 6ed8716..2a8e0ef 100644
--- a/contrib/optimizations/inflate.c
+++ b/contrib/optimizations/inflate.c
@@ -1488,8 +1488,9 @@
if (copy == Z_NULL) return Z_MEM_ERROR;
window = Z_NULL;
if (state->window != Z_NULL) {
- window = (unsigned char FAR *)
- ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
+ window = (unsigned char FAR *)ZALLOC(
+ source, (1U << state->wbits) + CHUNKCOPY_CHUNK_SIZE,
+ sizeof(unsigned char));
if (window == Z_NULL) {
ZFREE(source, copy);
return Z_MEM_ERROR;