Correctly handle writes beyond the end of the archive entry
(as determined by the initial size given to the header). Libarchive recently changed to correctly return the amount of data actually consumed in this case, which revealed this bug in bsdtar.
This commit is contained in:
parent
a47cbc19d4
commit
3cdd817959
@ -851,11 +851,19 @@ write_file_data(struct bsdtar *bsdtar, struct archive *a, int fd)
|
||||
bytes_read = read(fd, buff, sizeof(buff));
|
||||
while (bytes_read > 0) {
|
||||
bytes_written = archive_write_data(a, buff, bytes_read);
|
||||
if (bytes_written <= 0) {
|
||||
if (bytes_written < 0) {
|
||||
/* Write failed; this is bad */
|
||||
bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
|
||||
return (-1);
|
||||
}
|
||||
if (bytes_written < bytes_read) {
|
||||
/* Write was truncated; warn but continue. */
|
||||
bsdtar_warnc(bsdtar, 0,
|
||||
"Truncated write; file may have grown while being archived.");
|
||||
/* Make bsdtar return a final error because of this. */
|
||||
bsdtar->return_value = 1;
|
||||
return (0);
|
||||
}
|
||||
bytes_read = read(fd, buff, sizeof(buff));
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user