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