]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
ZIP reader: support LZMA_STREAM_END marker in 'lzma alone' files 1297/head
authorGrzegorz Antoniak <ga@anadoxin.org>
Mon, 23 Dec 2019 07:20:28 +0000 (08:20 +0100)
committerGrzegorz Antoniak <ga@anadoxin.org>
Mon, 23 Dec 2019 07:20:28 +0000 (08:20 +0100)
It appears that ZIPX files with type 14 stream ('lzma alone') can
contain LZMA_STREAM_END markers at the end of the stream. The ZIP reader
was displaying an "unknown error 1" status after encountering such
marker.

The fix handles such case, and the reader doesn't return error status
anymore. Thus it should be possible to unpack files that contain the
LZMA_STREAM_END marker at the end of the stream.

Fixes #1257

libarchive/archive_read_support_format_zip.c

index 9934bf1504dc639f5d7e51fecdae421bf878bc33..6581ca0acf6dee47b351942caf51256d1d03b0a2 100644 (file)
@@ -1797,6 +1797,23 @@ zip_read_data_zipx_lzma_alone(struct archive_read *a, const void **buff,
                            "lzma data error (error %d)", (int) lz_ret);
                        return (ARCHIVE_FATAL);
 
+               /* This case is optional in lzma alone format. It can happen,
+                * but most of the files don't have it. (GitHub #1257) */
+               case LZMA_STREAM_END:
+                       lzma_end(&zip->zipx_lzma_stream);
+                       zip->zipx_lzma_valid = 0;
+                       if((int64_t) zip->zipx_lzma_stream.total_in !=
+                           zip->entry_bytes_remaining)
+                       {
+                               archive_set_error(&a->archive,
+                                   ARCHIVE_ERRNO_MISC,
+                                   "lzma alone premature end of stream");
+                               return (ARCHIVE_FATAL);
+                       }
+
+                       zip->end_of_entry = 1;
+                       break;
+
                case LZMA_OK:
                        break;