From 5013bf78c88188005e9d4950faf2ff91663159b6 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Fri, 17 Apr 2020 18:17:59 +0200 Subject: [PATCH] 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. --- ext/solv_xfopen.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) -- 2.47.2