tar: Skip over data before processing the next entry
When we selectively process entries from the archive, ensure that we jump over the data section of each uninteresting entry before going on to process the next entry. Not doing so, leaves the file stream pointer in the wrong place.
This commit is contained in:
parent
2fc73e410c
commit
7a0d9fb3ea
11
tar.c
11
tar.c
|
@ -323,17 +323,22 @@ xt(int argc, char *argv[], int (*fn)(char *, ssize_t, char[BLKSIZ]))
|
||||||
snprintf(fname + n, sizeof(fname) - n, "%.*s",
|
snprintf(fname + n, sizeof(fname) - n, "%.*s",
|
||||||
(int)sizeof(h->name), h->name);
|
(int)sizeof(h->name), h->name);
|
||||||
|
|
||||||
|
if ((size = strtol(h->size, &p, 8)) < 0 || *p != '\0')
|
||||||
|
eprintf("strtol %s: invalid number\n", h->size);
|
||||||
|
|
||||||
if (argc) {
|
if (argc) {
|
||||||
/* only extract the given files */
|
/* only extract the given files */
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
if (!strcmp(argv[i], fname))
|
if (!strcmp(argv[i], fname))
|
||||||
break;
|
break;
|
||||||
if (i == argc)
|
if (i == argc) {
|
||||||
|
for (; size > 0; size -= BLKSIZ)
|
||||||
|
if (fread(b, BLKSIZ, 1, tarfile) != 1)
|
||||||
|
eprintf("fread %s:", tarfilename);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((size = strtol(h->size, &p, 8)) < 0 || *p != '\0')
|
|
||||||
eprintf("strtol %s: invalid number\n", h->size);
|
|
||||||
fn(fname, size, b);
|
fn(fname, size, b);
|
||||||
}
|
}
|
||||||
if (ferror(tarfile))
|
if (ferror(tarfile))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user