1
0
mirror of https://git.tukaani.org/xz.git synced 2026-10-31 03:14:56 +00:00

liblzma: mt dec: Protect progress_in update with mutex

Worker threads update coder->progress_in while holding coder->mutex, but
the main thread updated the same field without the mutex while decoding
the next Block Header. ThreadSanitizer reported the concurrent writes and
lzma_get_progress() under-reported input progress by one Block.

All other coder->progress_in/progress_out accesses in stream_decode_mt()
are done when the worker threads aren't active, so only the access in
SEQ_BLOCK_HEADER needs to lock coder->mutex.

Co-authored-by: Lasse Collin <lasse.collin@tukaani.org>
Fixes: 4cce3e27f529 ("liblzma: Add threaded .xz decompressor.")
Closes: https://github.com/tukaani-project/xz/pull/243
This commit is contained in:
Trithem90 2026-09-03 19:52:23 +02:00 committed by Lasse Collin
parent 5121d1aed8
commit c6e3aadbb5
No known key found for this signature in database
GPG Key ID: 38EE757D69184620

View File

@ -1068,7 +1068,12 @@ stream_decode_mt(void *coder_ptr, const lzma_allocator *allocator,
const size_t in_old = *in_pos; const size_t in_old = *in_pos;
const lzma_ret ret = decode_block_header(coder, allocator, const lzma_ret ret = decode_block_header(coder, allocator,
in, in_pos, in_size); in, in_pos, in_size);
coder->progress_in += *in_pos - in_old;
// Worker threads may finish earlier Blocks and need to update
// coder->progress_in at the same time with us.
mythread_sync(coder->mutex) {
coder->progress_in += *in_pos - in_old;
}
if (ret == LZMA_OK) { if (ret == LZMA_OK) {
// We didn't decode the whole Block Header yet. // We didn't decode the whole Block Header yet.