projects/linux·commit eb0cf3e1

Decompressors: validate match distance in decompress_unlzma.c

eb0cf3e1 · Lasse Collin <[email protected]> · 2011-01-12 17:01:19 -08:00

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]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Alain Knaff <[email protected]>
Cc: Albin Tonnerre <[email protected]>
Cc: Phillip Lougher <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Commit
eb0cf3e19b4940a2d26dcdea03510ae16a580fcd
Parents
528941ca

Changes

1 files changed · +3 −0

FileStatusAddDelContent
lib/decompress_unlzma.cmodified+3−0View file

lib/decompress_unlzma.c

View file
diff --git a/lib/decompress_unlzma.c b/lib/decompress_unlzma.c
index f30c899..476c65a 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;