lib/lzo: fix ambiguous encoding bug in lzo-rle

In some rare cases, for input data over 32 KB, lzo-rle could encode two
different inputs to the same compressed representation, so that
decompression is then ambiguous (i.e.  data may be corrupted - although
zram is not affected because it operates over 4 KB pages).

This modifies the compressor without changing the decompressor or the
bitstream format, such that:

 - there is no change to how data produced by the old compressor is

 - an old decompressor will correctly decode data from the updated

 - performance and compression ratio are not affected

 - we avoid introducing a new bitstream format

In testing over 12.8M real-world files totalling 903 GB, three files
were affected by this bug.  I also constructed 37M semi-random 64 KB
files totalling 2.27 TB, and saw no affected files.  Finally I tested
over files constructed to contain each of the ~1024 possible bad input
sequences; for all of these cases, updated lzo-rle worked correctly.

There is no significant impact to performance or compression ratio.

Signed-off-by: Dave Rodgman <>
Signed-off-by: Andrew Morton <>
Cc: Mark Rutland <>
Cc: Dave Rodgman <>
Cc: Willy Tarreau <>
Cc: Sergey Senozhatsky <>
Cc: Markus F.X.J. Oberhumer <>
Cc: Minchan Kim <>
Cc: Nitin Gupta <>
Cc: Chao Yu <>
Cc: <>
Signed-off-by: Linus Torvalds <>
2 files changed