From c8d40b27de8d49cde845c55f5e309b22217a03b8 Mon Sep 17 00:00:00 2001 From: Grzegorz Antoniak Date: Mon, 23 Dec 2019 08:20:28 +0100 Subject: [PATCH] ZIP reader: support LZMA_STREAM_END marker in 'lzma alone' files 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libarchive/archive_read_support_format_zip.c b/libarchive/archive_read_support_format_zip.c index 9934bf150..6581ca0ac 100644 --- a/libarchive/archive_read_support_format_zip.c +++ b/libarchive/archive_read_support_format_zip.c @@ -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; -- 2.47.2