9184f0
diff --git a/zlib/inflate.c b/zlib/inflate.c
9184f0
index e43abd9..bd33c19 100644
9184f0
--- a/zlib/inflate.c
9184f0
+++ b/zlib/inflate.c
9184f0
@@ -740,8 +740,9 @@ int flush;
9184f0
                 if (copy > have) copy = have;
9184f0
                 if (copy) {
9184f0
                     if (state->head != Z_NULL &&
9184f0
-                        state->head->extra != Z_NULL) {
9184f0
-                        len = state->head->extra_len - state->length;
9184f0
+                        state->head->extra != Z_NULL &&
9184f0
+                        (len = state->head->extra_len - state->length) <
9184f0
+			    state->head->extra_max) {
9184f0
                         zmemcpy(state->head->extra + len, next,
9184f0
                                 len + copy > state->head->extra_max ?
9184f0
                                 state->head->extra_max - len : copy);