From eb0cf3e19b4940a2d26dcdea03510ae16a580fcd Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Wed, 12 Jan 2011 17:01:19 -0800 Subject: Decompressors: validate match distance in decompress_unlzma.c Validate the newly decoded distance (rep0) in process_bit1(). This is to detect corrupt LZMA data quickly. The old code can run for long time producing garbage until it hits the end of the input. Signed-off-by: Lasse Collin Cc: "H. Peter Anvin" Cc: Alain Knaff Cc: Albin Tonnerre Cc: Phillip Lougher Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- lib/decompress_unlzma.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/decompress_unlzma.c b/lib/decompress_unlzma.c index f30c899241e..476c65af970 100644 --- a/lib/decompress_unlzma.c +++ b/lib/decompress_unlzma.c @@ -522,6 +522,9 @@ static inline int INIT process_bit1(struct writer *wr, struct rc *rc, cst->rep0 = pos_slot; if (++(cst->rep0) == 0) return 0; + if (cst->rep0 > wr->header->dict_size + || cst->rep0 > get_pos(wr)) + return -1; } len += LZMA_MATCH_MIN_LEN; -- cgit v1.2.3