From: Hans Kristian Rosbach Date: Fri, 24 Mar 2017 13:27:59 +0000 (+0100) Subject: Prevent potential division-by-zero in gzfwrite and gzfread. X-Git-Tag: 1.9.9-b1~664 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eeb195e16d075812db0f6030a66bb373bbb6e5e4;p=thirdparty%2Fzlib-ng.git Prevent potential division-by-zero in gzfwrite and gzfread. --- diff --git a/gzread.c b/gzread.c index c8ec08fbd..7319365bf 100644 --- a/gzread.c +++ b/gzread.c @@ -378,6 +378,10 @@ size_t ZEXPORT gzfread(void *buf, size_t size, size_t nitems, gzFile file) { size_t len; gz_state *state; + /* Exit early if size is zero, also prevents potential division by zero */ + if (size == 0) + return 0; + /* get internal structure */ if (file == NULL) return 0; diff --git a/gzwrite.c b/gzwrite.c index 80305261b..cfaefb145 100644 --- a/gzwrite.c +++ b/gzwrite.c @@ -248,6 +248,10 @@ size_t ZEXPORT gzfwrite(void const *buf, size_t size, size_t nitems, gzFile file size_t len; gz_state *state; + /* Exit early if size is zero, also prevents potential division by zero */ + if (size == 0) + return 0; + /* get internal structure */ if (file == NULL) return 0;