From: Lasse Collin Date: Fri, 11 Nov 2011 13:34:24 +0000 (+0100) Subject: Decompressors: validate match distance in unlzma.c X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=24bde2170dde6ed1a4a3de7c96a019eb4dae9501;p=xen.git Decompressors: validate match distance in unlzma.c From: Lasse Collin 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 Signed-off-by: Jan Beulich Acked-by: Keir Fraser Committed-by: Jan Beulich --- diff --git a/xen/common/unlzma.c b/xen/common/unlzma.c index 6dcd7ba20b..87b9e0a964 100644 --- a/xen/common/unlzma.c +++ b/xen/common/unlzma.c @@ -516,6 +516,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;