3fda7c
From eff308af425b67093bab25f80f1ae950166bece1 Mon Sep 17 00:00:00 2001
3fda7c
From: Mark Adler <fork@madler.net>
3fda7c
Date: Sat, 30 Jul 2022 15:51:11 -0700
3fda7c
Subject: [PATCH] Fix a bug when getting a gzip header extra field with
3fda7c
 inflate().
3fda7c
3fda7c
If the extra field was larger than the space the user provided with
3fda7c
inflateGetHeader(), and if multiple calls of inflate() delivered
3fda7c
the extra header data, then there could be a buffer overflow of the
3fda7c
provided space. This commit assures that provided space is not
3fda7c
exceeded.
3fda7c
---
3fda7c
 inflate.c | 5 +++--
3fda7c
 1 file changed, 3 insertions(+), 2 deletions(-)
3fda7c
3fda7c
diff --git a/inflate.c b/inflate.c
3fda7c
index 7be8c63..7a72897 100644
3fda7c
--- a/inflate.c
3fda7c
+++ b/inflate.c
3fda7c
@@ -763,9 +763,10 @@ int flush;
3fda7c
                 copy = state->length;
3fda7c
                 if (copy > have) copy = have;
3fda7c
                 if (copy) {
3fda7c
+                    len = state->head->extra_len - state->length;
3fda7c
                     if (state->head != Z_NULL &&
3fda7c
-                        state->head->extra != Z_NULL) {
3fda7c
-                        len = state->head->extra_len - state->length;
3fda7c
+                        state->head->extra != Z_NULL &&
3fda7c
+                        len < state->head->extra_max) {
3fda7c
                         zmemcpy(state->head->extra + len, next,
3fda7c
                                 len + copy > state->head->extra_max ?
3fda7c
                                 state->head->extra_max - len : copy);
3fda7c
-- 
3fda7c
2.35.3
3fda7c