]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xz: Fix --single-stream with an empty .xz Stream.
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 25 Oct 2022 20:09:11 +0000 (23:09 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 11 Nov 2022 11:38:34 +0000 (13:38 +0200)
Example:

    $ xz -dc --single-stream good-0-empty.xz
    xz: good-0-empty.xz: Internal error (bug)

The code, that is tries to catch some input file issues early,
didn't anticipate LZMA_STREAM_END which is possible in that
code only when --single-stream is used.

src/xz/coder.c

index bc9055943382a7ad4efa34aca7e089c068968351..51cd3ef0d12f1ad7664b65b7da08e899ee89f87c 100644 (file)
@@ -557,6 +557,15 @@ coder_init(file_pair *pair)
                                        == LZMA_UNSUPPORTED_CHECK)
                                message_warning("%s: %s", pair->src_name,
                                                message_strm(ret));
+
+                       // With --single-stream lzma_code won't wait for
+                       // LZMA_FINISH and thus it can return LZMA_STREAM_END
+                       // if the file has no uncompressed data inside.
+                       // So treat LZMA_STREAM_END as LZMA_OK here.
+                       // When lzma_code() is called again in coder_normal()
+                       // it will return LZMA_STREAM_END again.
+                       if (ret == LZMA_STREAM_END)
+                               ret = LZMA_OK;
                }
 #endif
        }