From 3cdd817959d317e0531b737d1dc174f8262c187c Mon Sep 17 00:00:00 2001 From: kientzle Date: Wed, 14 Feb 2007 08:16:08 +0000 Subject: 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. --- usr.bin/tar/write.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c index 09016dd..d7fbcfb 100644 --- a/usr.bin/tar/write.c +++ b/usr.bin/tar/write.c @@ -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; -- cgit v1.1