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.
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 (s < n)
+ goto again;
+
+ return s;
}
static ssize_t