adenilson / rpms / zlib

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