bin/108990: incorrect error handling in tar(1) for files that
change size
Tim Kientzle
kientzle at freebsd.org
Sun Feb 11 00:50:10 UTC 2007
Ade Lovett wrote:
> Synopsis: incorrect error handling in tar(1) for files that change size
>
> http://www.freebsd.org/cgi/query-pr.cgi?pr=108990
This is caused by a recent fix to libarchive, which no longer
silently consumes data written past the end of the entry.
I think the patch presented in the PR is acceptable,
but I like this better. Any concerns?
Index: write.c
===================================================================
--- write.c (revision 120)
+++ write.c (working copy)
@@ -851,11 +851,19 @@
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. */
+ bsdtar->return_value = 1;
+ return (0);
+ }
bytes_read = read(fd, buff, sizeof(buff));
}
return 0;
More information about the freebsd-bugs
mailing list