From: Michael Schroeder Date: Fri, 17 Apr 2020 16:17:59 +0000 (+0200) Subject: Return a read error for truncated gzip files X-Git-Tag: 0.7.12~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5013bf78c88188005e9d4950faf2ff91663159b6;p=thirdparty%2Flibsolv.git Return a read error for truncated gzip files The gzread() helper does not return an error if a file is truncated. This is done to allow reading a file that that is being concurrently written. As workaround, get the error code if an EOF is reached and treat Z_BUF_ERROR as read error. --- diff --git a/ext/solv_xfopen.c b/ext/solv_xfopen.c index 9aab68b2..4bb4628c 100644 --- a/ext/solv_xfopen.c +++ b/ext/solv_xfopen.c @@ -61,7 +61,15 @@ static FILE *cookieopen(void *cookie, const char *mode, static ssize_t cookie_gzread(void *cookie, char *buf, size_t nbytes) { - return gzread((gzFile)cookie, buf, nbytes); + ssize_t r = gzread((gzFile)cookie, buf, nbytes); + if (r == 0) + { + int err = 0; + gzerror((gzFile)cookie, &err); + if (err == Z_BUF_ERROR) + r = -1; + } + return r; } static ssize_t cookie_gzwrite(void *cookie, const char *buf, size_t nbytes)