2010-11-23 10:26:20

by Lasse Collin

[permalink] [raw]
Subject: [PATCH 4/4] Decompressors: Validate match distance in decompress_unlzma.c

From: Lasse Collin <[email protected]>

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 <[email protected]>
---

--- linux-2.6.37-rc3/lib/decompress_unlzma.c.orig 2010-11-23 11:11:58.000000000 +0200
+++ linux-2.6.37-rc3/lib/decompress_unlzma.c 2010-11-23 11:13:30.000000000 +0200
@@ -528,6 +528,9 @@ static inline int INIT process_bit1(stru
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;