Commit b02fdc66 for xz
commit b02fdc66b4f9fcdf2f7316a087ee5e94ae377986
Author: Lasse Collin <lasse.collin@tukaani.org>
Date: Mon Nov 23 18:02:48 2026 +0200
liblzma: Silence Valgrind and -fsanitize=memory with a preset dictionary
lzma_memcmplen() reads a few extra bytes, but eventually it ignores them.
Valgrind and -fsanitize=memory don't see it and still complained about
use of uninitialized values. The initialization was in fill_window(), but
it had been forgotten from the preset dictionary handling.
Fixes: 5db75054e900 ("liblzma: Use lzma_memcmplen() in the match finders.")
Reported-by: Yousef Mahmoud <yosefkhalil610@gmail.com>
Link: https://github.com/tukaani-project/xz/pull/247#issuecomment-6879866832
diff --git a/src/liblzma/lz/lz_encoder.c b/src/liblzma/lz/lz_encoder.c
index aaa1466c..3ea9ec21 100644
--- a/src/liblzma/lz/lz_encoder.c
+++ b/src/liblzma/lz/lz_encoder.c
@@ -446,6 +446,10 @@ lz_encoder_init(lzma_mf *mf, const lzma_allocator *allocator,
memcpy(mf->buffer, lz_options->preset_dict
+ lz_options->preset_dict_size - mf->write_pos,
mf->write_pos);
+
+ // Keep Valgrind and sanitizers happy.
+ memzero(mf->buffer + mf->write_pos, LZMA_MEMCMPLEN_EXTRA);
+
mf->action = LZMA_SYNC_FLUSH;
mf->skip(mf, mf->write_pos);
}