]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Make the end-of-archive detection work properly with the new
authorTim Kientzle <kientzle@gmail.com>
Sun, 19 Oct 2008 22:38:35 +0000 (18:38 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sun, 19 Oct 2008 22:38:35 +0000 (18:38 -0400)
strict read_ahead() semantics, which return a failure instead of
a short read at end-of-file.  This seems to be one of the very
few cases where the short read is actually informative.

SVN-Revision: 226

libarchive/archive_read_support_format_tar.c

index 44952381fc9f4841397634a7110ddf973e7a0fb7..0a649791a31dde133ebdea0c5640be332c1146d2 100644 (file)
@@ -555,15 +555,19 @@ tar_read_header(struct archive_read *a, struct tar *tar,
        bytes = (a->decompressor->read_ahead)(a, &h, 512);
        if (bytes < 0)
                return (bytes);
-       if (bytes == 0) {
-               /*
-                * An archive that just ends without a proper
-                * end-of-archive marker.  Yes, there are tar programs
-                * that do this; hold our nose and accept it.
-                */
-               return (ARCHIVE_EOF);
-       }
-       if (bytes < 512) {
+       if (bytes < 512) {  /* Short read or EOF. */
+               /* Try requesting just one byte and see what happens. */
+               bytes = (a->decompressor->read_ahead)(a, &h, 1);
+               if (bytes == 0) {
+                       /*
+                        * The archive ends at a 512-byte boundary but
+                        * without a proper end-of-archive marker.
+                        * Yes, there are tar writers that do this;
+                        * hold our nose and accept it.
+                        */
+                       return (ARCHIVE_EOF);
+               }
+               /* Archive ends with a partial block; this is bad. */
                archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
                    "Truncated tar archive");
                return (ARCHIVE_FATAL);