blob: 96ab563121c36962f6c91fe407d15e408134d175 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001From eff308af425b67093bab25f80f1ae950166bece1 Mon Sep 17 00:00:00 2001
2From: Mark Adler <fork@madler.net>
3Date: Sat, 30 Jul 2022 15:51:11 -0700
4Subject: [PATCH] Fix a bug when getting a gzip header extra field with inflate().
5
6If the extra field was larger than the space the user provided with
7inflateGetHeader(), and if multiple calls of inflate() delivered
8the extra header data, then there could be a buffer overflow of the
9provided space. This commit assures that provided space is not
10exceeded.
11
12CVE: CVE-2022-37434
13Upstream-Status: Backport [https://github.com/madler/zlib/commit/eff308af425b67093bab25f80f1ae950166be]
14Signed-off-by: Khem Raj <raj.khem@gmail.com>
15---
16 inflate.c | 5 +++--
17 1 file changed, 3 insertions(+), 2 deletions(-)
18
19diff --git a/inflate.c b/inflate.c
20index 7be8c63..7a72897 100644
21--- a/inflate.c
22+++ b/inflate.c
23@@ -763,9 +763,10 @@ int flush;
24 copy = state->length;
25 if (copy > have) copy = have;
26 if (copy) {
27+ len = state->head->extra_len - state->length;
28 if (state->head != Z_NULL &&
29- state->head->extra != Z_NULL) {
30- len = state->head->extra_len - state->length;
31+ state->head->extra != Z_NULL &&
32+ len < state->head->extra_max) {
33 zmemcpy(state->head->extra + len, next,
34 len + copy > state->head->extra_max ?
35 state->head->extra_max - len : copy);
36--
372.37.2
38