]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Allow empty files (after filters) in bsdcat command. 87/head
authorSebastian Freundt <freundt@ga-group.nl>
Tue, 12 Aug 2014 14:55:28 +0000 (14:55 +0000)
committerSebastian Freundt <freundt@ga-group.nl>
Wed, 13 Aug 2014 07:05:12 +0000 (07:05 +0000)
This changeset fixes an issue with empty compressed files, i.e.
files that after inflating are of size 0:  bsdcat would report
unrecognized archive format for those because the raw reader is
unable to handle files of zero length.

cat/bsdcat.c

index 3ffd99ab58d69442123b3be71a61678067840244..8756a8b8868ac46cd0d65c286cd4a2bd3b29c3b0 100644 (file)
@@ -62,6 +62,7 @@ bsdcat_next()
 {
        a = archive_read_new();
        archive_read_support_filter_all(a);
+       archive_read_support_format_empty(a);
        archive_read_support_format_raw(a);
 }
 
@@ -76,10 +77,20 @@ bsdcat_print_error(void)
 void
 bsdcat_read_to_stdout(char* filename)
 {
-       if ((archive_read_open_filename(a, filename, BYTES_PER_BLOCK) != ARCHIVE_OK)
-           || (archive_read_next_header(a, &ae) != ARCHIVE_OK)
-           || (archive_read_data_into_fd(a, 1) != ARCHIVE_OK))
+       int r;
+
+       if (archive_read_open_filename(a, filename, BYTES_PER_BLOCK) != ARCHIVE_OK)
+               goto err;
+       else if (r = archive_read_next_header(a, &ae),
+                r != ARCHIVE_OK && r != ARCHIVE_EOF)
+               goto err;
+       else if (r == ARCHIVE_EOF)
+               /* for empty payloads don't try and read data */
+               ;
+       else if (archive_read_data_into_fd(a, 1) != ARCHIVE_OK) {
+       err:
                bsdcat_print_error();
+       }
        if (archive_read_free(a) != ARCHIVE_OK)
                bsdcat_print_error();
 }