From e6460141851d3af158eefe9ade4cff75017e3a87 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 19 May 2019 23:18:26 -0500 Subject: Fix tar sparse extract with extension blocks. --- tests/tar.test | 1 - toys/posix/tar.c | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/tar.test b/tests/tar.test index b70bf3cd..2046e51a 100644 --- a/tests/tar.test +++ b/tests/tar.test @@ -220,7 +220,6 @@ BLOCKS=7 testing "sparse double overflow" "$TAR --sparse fweep | $SUM" \ tar c --sparse fweep > fweep.tar FWEEP=$(du fweep) -exit 1 rm fweep testing "sparse extract" "tar xf fweep.tar && du fweep" "$FWEEP\n" "" "" rm fweep fweep.tar diff --git a/toys/posix/tar.c b/toys/posix/tar.c index ecc378b7..10535f37 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -439,7 +439,7 @@ static void sendfile_sparse(int fd) long long len, used = 0, sent; int i = 0, j; - for (;;) { + do { if (TT.sparselen) { if (!TT.sparse[i*2+1]) continue; // Seek past holes or fill output with zeroes. @@ -465,9 +465,7 @@ error: break; } - - if (++i >= TT.sparselen) break; - } + } while (++imax || !*s) { if (!(*sparse ? sparse[504] : ((char *)&tar)[482])) break; xreadall(TT.fd, s = sparse, 512); - max = 42; + max = 41; i = 0; } - // Load next entry TT.sparse[TT.sparselen++] = otoi(s, 12); s += 12; -- cgit v1.2.3