|
| 1 | +From b49d2f0b84d424ec7fbf47138bf6acc6b18e1b0d Mon Sep 17 00:00:00 2001 |
| 2 | +From: tabudz <tanb74653@gmail.com> |
| 3 | +Date: Tue, 18 Feb 2025 11:28:15 +0800 |
| 4 | +Subject: [PATCH] Fix a bug when getting a gzip header extra field with |
| 5 | + inflate(). If the extra field was larger than the space the user provided |
| 6 | + with inflateGetHeader(), and if multiple calls of inflate() delivered the |
| 7 | + extra header data, then there could be a buffer overflow of the provided |
| 8 | + space. This commit assures that provided space is not exceeded. |
| 9 | + |
| 10 | +Upstream Reference: https://github.com/radareorg/radare2/pull/23969/commits/b49d2f0b84d424ec7fbf47138bf6acc6b18e1b0d |
| 11 | +--- |
| 12 | + inflate.c | 5 +++-- |
| 13 | + 1 file changed, 3 insertions(+), 2 deletions(-) |
| 14 | + |
| 15 | +diff --git a/inflate.c b/inflate.c |
| 16 | +index e9ed74cff3279..2ecfb4876d155 100644 |
| 17 | +--- a/inflate.c |
| 18 | ++++ b/inflate.c |
| 19 | +@@ -755,9 +755,10 @@ int ZEXPORT inflate(z_streamp strm, int flush) |
| 20 | + copy = state->length; |
| 21 | + if (copy > have) copy = have; |
| 22 | + if (copy) { |
| 23 | ++ len = state->head->extra_len - state->length; |
| 24 | + if (state->head != Z_NULL && |
| 25 | +- state->head->extra != Z_NULL) { |
| 26 | +- len = state->head->extra_len - state->length; |
| 27 | ++ state->head->extra != Z_NULL && |
| 28 | ++ len < state->head->extra_max) { |
| 29 | + zmemcpy(state->head->extra + len, next, |
| 30 | + len + copy > state->head->extra_max ? |
| 31 | + state->head->extra_max - len : copy); |
0 commit comments