Skip to content

Commit 5013bf7

Browse files
committed
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.
1 parent b198a12 commit 5013bf7

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

ext/solv_xfopen.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ static FILE *cookieopen(void *cookie, const char *mode,
6161

6262
static ssize_t cookie_gzread(void *cookie, char *buf, size_t nbytes)
6363
{
64-
return gzread((gzFile)cookie, buf, nbytes);
64+
ssize_t r = gzread((gzFile)cookie, buf, nbytes);
65+
if (r == 0)
66+
{
67+
int err = 0;
68+
gzerror((gzFile)cookie, &err);
69+
if (err == Z_BUF_ERROR)
70+
r = -1;
71+
}
72+
return r;
6573
}
6674

6775
static ssize_t cookie_gzwrite(void *cookie, const char *buf, size_t nbytes)

0 commit comments

Comments
 (0)