[PATCH] XZ decompressor: Fix decoding of empty LZMA2 streams

Lasse Collin
2011-05-01T16:48:42Z

From: Lasse Collin <lasse.collin@tukaani.org>

The old code considered valid empty LZMA2 streams to be corrupt.
Note that a typical empty .xz file has no LZMA2 data at all,
and thus most .xz files having no uncompressed data are handled
correctly even without this fix.

Signed-off-by: Lasse Collin <lasse.collin@tukaani.org>
---

lib/xz/xz_dec_lzma2.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff -uprN linux-2.6.39-rc5-git5.orig/lib/xz/xz_dec_lzma2.c linux-2.6.39-rc5-git5/lib/xz/xz_dec_lzma2.c
--- linux-2.6.39-rc5-git5.orig/lib/xz/xz_dec_lzma2.c 2011-05-01 17:56:38.000000000 +0300
+++ linux-2.6.39-rc5-git5/lib/xz/xz_dec_lzma2.c 2011-05-01 18:06:03.000000000 +0300
@@ -969,6 +969,9 @@ XZ_EXTERN enum xz_ret xz_dec_lzma2_run(s
*/
tmp = b->in[b->in_pos++];

+ if (tmp == 0x00)
+ return XZ_STREAM_END;
+
if (tmp >= 0xE0 || tmp == 0x01) {
s->lzma2.need_props = true;
s->lzma2.need_dict_reset = false;
@@ -1001,9 +1004,6 @@ XZ_EXTERN enum xz_ret xz_dec_lzma2_run(s
lzma_reset(s);
}
} else {
- if (tmp == 0x00)
- return XZ_STREAM_END;
-
if (tmp > 0x02)
return XZ_DATA_ERROR;