]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Return a read error for truncated gzip files
authorMichael Schroeder <mls@suse.de>
Fri, 17 Apr 2020 16:17:59 +0000 (18:17 +0200)
committerMichael Schroeder <mls@suse.de>
Fri, 17 Apr 2020 16:17:59 +0000 (18:17 +0200)
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

index 9aab68b2042eb2ee3c142b1b104565bbdd6303e8..4bb4628cdcd8cd5c7592dd5d4ae5e5e37d775329 100644 (file)
@@ -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)