Willy Gfn wrote:
> Hello,
> 
> The attached patch makes tar read again from a pipe in case less bytes
> are read than expected.
> This prevent a bug where it fails to extract files correctly because
> not enough bytes are read from, eg, a pipe hooked to a decompression
> program.

Just realised there is a bug in my patch. We should only keep reading
if read() returns more than 0 bytes, otherwise the functions returns.

Updated patch attached.

Cheers!
diff --git a/tar.c b/tar.c
index 4a81f8f..f2649f1 100644
--- a/tar.c
+++ b/tar.c
@@ -155,16 +155,21 @@ decomp(int fd, const char *tool, const char *flags)
 static ssize_t
 eread(int fd, void *buf, size_t n)
 {
-       ssize_t r;
+       char *tmp = buf;
+       ssize_t r, s = 0;
 
 again:
-       r = read(fd, buf, n);
+       r = read(fd, tmp + s, n - s);
+       s += r;
        if (r < 0) {
                if (errno == EINTR)
                        goto again;
                eprintf("read:");
        }
-       return r;
+       if (r && s < n)
+               goto again;
+
+       return s;
 }
 
 static ssize_t

Reply via email to