--- zlib-1.2.12/inflate.c.old 2022-08-09 10:30:18.831225181 +0000 +++ zlib-1.2.12/inflate.c 2022-08-09 10:29:33.251225181 +0000 @@ -792,8 +792,9 @@ int flush; if (copy > have) copy = have; if (copy) { if (state->head != Z_NULL && - state->head->extra != Z_NULL) { - len = state->head->extra_len - state->length; + state->head->extra != Z_NULL && + (len = state->head->extra_len - state->length) < + state->head->extra_max) { zmemcpy(state->head->extra + len, next, len + copy > state->head->extra_max ? state->head->extra_max - len : copy);