]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Check the return value of lzma_index_append() in threaded encoder.
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 22 Feb 2022 00:04:18 +0000 (02:04 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 22 Feb 2022 00:04:18 +0000 (02:04 +0200)
If lzma_index_append() failed (most likely memory allocation failure)
it could have gone unnoticed and the resulting .xz file would have
an incorrect Index. Decompressing such a file would produce the
correct uncompressed data but then an error would occur when
verifying the Index field.

src/liblzma/common/stream_encoder_mt.c

index 91cda9981a4c213f98c03140348a101fa184d4cf..24addd40bb527ffab8d561b912c61327454ad8ad 100644 (file)
@@ -732,6 +732,10 @@ stream_encode_mt(void *coder_ptr, const lzma_allocator *allocator,
                                ret = lzma_index_append(coder->index,
                                                allocator, unpadded_size,
                                                uncompressed_size);
+                               if (ret != LZMA_OK) {
+                                       threads_stop(coder, false);
+                                       return ret;
+                               }
 
                                // If we didn't fill the output buffer yet,
                                // try to read more data. Maybe the next
@@ -741,8 +745,7 @@ stream_encode_mt(void *coder_ptr, const lzma_allocator *allocator,
                        }
 
                        if (ret != LZMA_OK) {
-                               // coder->thread_error was set or
-                               // lzma_index_append() failed.
+                               // coder->thread_error was set.
                                threads_stop(coder, false);
                                return ret;
                        }