Merge branch 'jn/5.1.1alpha+20120614'

Recent changes from upstream, including a documentation update and
small correctness fix for the "minimal version to decode" field.
Thanks to Lasse Collin for advice about which patches to apply.

After these changes, the xz and liblzma API and ABI match 5.1.2alpha,
except that no features that were not already present in Debian sid
have been added.
diff --git a/debian/changelog b/debian/changelog
index f3a75e8..5f8a175 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,12 @@
 xz-utils (5.1.1alpha+20120614-1.1) unstable; urgency=low
 
+  * liblzma: report a LZMA_DATA_ERROR when range encoded data starts
+    with a nonzero byte.  This is a sanity check to catch malformed
+    files that no known encoders produce.
+  * xz -v -v --list: Support for decompressing blocks with zero-length
+    uncompressed data was added in xz 5.0.2, not 5.0.3.
+  * xz.1: "xz --robot -v -v --list" gained a "minimum xz version to
+    decompress" field.
   * xz-utils/README.Debian: Document differences from upstream.
     Closes: #685217.
 
diff --git a/debian/patches/decoder-check-first-0x00 b/debian/patches/decoder-check-first-0x00
new file mode 100644
index 0000000..442e318
--- /dev/null
+++ b/debian/patches/decoder-check-first-0x00
@@ -0,0 +1,69 @@
+From: Lasse Collin <lasse.collin@tukaani.org>
+Date: Thu, 28 Jun 2012 10:47:49 +0300
+Subject: liblzma: Check that the first byte of range encoded data is 0x00.
+
+It is just to be more pedantic and thus perhaps catch broken
+files slightly earlier.
+
+Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
+---
+ src/liblzma/lzma/lzma_decoder.c        |    8 ++++++--
+ src/liblzma/rangecoder/range_decoder.h |   12 +++++++++---
+ 2 files changed, 15 insertions(+), 5 deletions(-)
+
+diff --git a/src/liblzma/lzma/lzma_decoder.c b/src/liblzma/lzma/lzma_decoder.c
+index 5abbc0d..b8f9317 100644
+--- a/src/liblzma/lzma/lzma_decoder.c
++++ b/src/liblzma/lzma/lzma_decoder.c
+@@ -289,8 +289,12 @@ lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr,
+ 	// Initialization //
+ 	////////////////////
+ 
+-	if (!rc_read_init(&coder->rc, in, in_pos, in_size))
+-		return LZMA_OK;
++	{
++		const lzma_ret ret = rc_read_init(
++				&coder->rc, in, in_pos, in_size);
++		if (ret != LZMA_STREAM_END)
++			return ret;
++	}
+ 
+ 	///////////////
+ 	// Variables //
+diff --git a/src/liblzma/rangecoder/range_decoder.h b/src/liblzma/rangecoder/range_decoder.h
+index fb96180..e0b051f 100644
+--- a/src/liblzma/rangecoder/range_decoder.h
++++ b/src/liblzma/rangecoder/range_decoder.h
+@@ -25,20 +25,26 @@ typedef struct {
+ 
+ 
+ /// Reads the first five bytes to initialize the range decoder.
+-static inline bool
++static inline lzma_ret
+ rc_read_init(lzma_range_decoder *rc, const uint8_t *restrict in,
+ 		size_t *restrict in_pos, size_t in_size)
+ {
+ 	while (rc->init_bytes_left > 0) {
+ 		if (*in_pos == in_size)
+-			return false;
++			return LZMA_OK;
++
++		// The first byte is always 0x00. It could have been omitted
++		// in LZMA2 but it wasn't, so one byte is wasted in every
++		// LZMA2 chunk.
++		if (rc->init_bytes_left == 5 && in[*in_pos] != 0x00)
++			return LZMA_DATA_ERROR;
+ 
+ 		rc->code = (rc->code << 8) | in[*in_pos];
+ 		++*in_pos;
+ 		--rc->init_bytes_left;
+ 	}
+ 
+-	return true;
++	return LZMA_STREAM_END;
+ }
+ 
+ 
+-- 
+1.7.9.6 (Apple Git-31.1)
+
diff --git a/debian/patches/man-date b/debian/patches/man-date
new file mode 100644
index 0000000..f43d3b7
--- /dev/null
+++ b/debian/patches/man-date
@@ -0,0 +1,25 @@
+From: Lasse Collin <lasse.collin@tukaani.org>
+Date: Fri, 22 Jun 2012 14:34:03 +0300
+Subject: xz: Update man page date to match the latest update.
+
+Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
+---
+ src/xz/xz.1 |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/xz/xz.1 b/src/xz/xz.1
+index 3ff89f0..cb8cd1e 100644
+--- a/src/xz/xz.1
++++ b/src/xz/xz.1
+@@ -5,7 +5,7 @@
+ .\" This file has been put into the public domain.
+ .\" You can do whatever you want with this file.
+ .\"
+-.TH XZ 1 "2011-04-11" "Tukaani" "XZ Utils"
++.TH XZ 1 "2012-05-27" "Tukaani" "XZ Utils"
+ .
+ .SH NAME
+ xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files
+-- 
+1.7.9.6 (Apple Git-31.1)
+
diff --git a/debian/patches/man-xz-lvv-minver b/debian/patches/man-xz-lvv-minver
new file mode 100644
index 0000000..8b2f44d
--- /dev/null
+++ b/debian/patches/man-xz-lvv-minver
@@ -0,0 +1,55 @@
+From: Lasse Collin <lasse.collin@tukaani.org>
+Date: Sun, 1 Jul 2012 18:44:33 +0300
+Subject: xz: Update the man page about the new field in --robot -lvv.
+
+Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
+---
+ src/xz/xz.1 |   18 +++++++++++++++++-
+ 1 file changed, 17 insertions(+), 1 deletion(-)
+
+diff --git a/src/xz/xz.1 b/src/xz/xz.1
+index cb8cd1e..4da09ba 100644
+--- a/src/xz/xz.1
++++ b/src/xz/xz.1
+@@ -5,7 +5,7 @@
+ .\" This file has been put into the public domain.
+ .\" You can do whatever you want with this file.
+ .\"
+-.TH XZ 1 "2012-05-27" "Tukaani" "XZ Utils"
++.TH XZ 1 "2012-07-01" "Tukaani" "XZ Utils"
+ .
+ .SH NAME
+ xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files
+@@ -1889,6 +1889,14 @@ or
+ .B no
+ indicating if all block headers have both compressed size and
+ uncompressed size stored in them
++.PP
++.I Since
++.B xz
++.I 5.1.2alpha:
++.IP 4. 4
++Minimum
++.B xz
++version required to decompress the file
+ .RE
+ .PD
+ .PP
+@@ -1939,6 +1947,14 @@ or
+ .B no
+ indicating if all block headers have both compressed size and
+ uncompressed size stored in them
++.PP
++.I Since
++.B xz
++.I 5.1.2alpha:
++.IP 12. 4
++Minimum
++.B xz
++version required to decompress the file
+ .RE
+ .PD
+ .PP
+-- 
+1.7.9.6 (Apple Git-31.1)
+
diff --git a/debian/patches/series b/debian/patches/series
index c5aebaf..8020937 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,7 @@
 abi-version-script
 abi-liblzma2-compat
 configure-liblzma2-compat
+man-date
+man-xz-lvv-minver
+xz-lvv-empty-block-minver
+decoder-check-first-0x00
diff --git a/debian/patches/xz-lvv-empty-block-minver b/debian/patches/xz-lvv-empty-block-minver
new file mode 100644
index 0000000..2c658d9
--- /dev/null
+++ b/debian/patches/xz-lvv-empty-block-minver
@@ -0,0 +1,38 @@
+From: Lasse Collin <lasse.collin@tukaani.org>
+Date: Wed, 4 Jul 2012 19:58:23 +0300
+Subject: xz: Fix the version number printed by xz -lvv.
+
+The decoder bug was fixed in 5.0.2 instead of 5.0.3.
+
+Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
+---
+ src/xz/list.c |    6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/src/xz/list.c b/src/xz/list.c
+index e71fbe2..a9e0adb 100644
+--- a/src/xz/list.c
++++ b/src/xz/list.c
+@@ -482,7 +482,7 @@ parse_block_header(file_pair *pair, const lzma_index_iter *iter,
+ 	// Determine the minimum XZ Utils version that supports this Block.
+ 	//
+ 	// Currently the only thing that 5.0.0 doesn't support is empty
+-	// LZMA2 Block. This bug was fixed in 5.0.3.
++	// LZMA2 Block. This decoder bug was fixed in 5.0.2.
+ 	{
+ 		size_t i = 0;
+ 		while (filters[i + 1].id != LZMA_VLI_UNKNOWN)
+@@ -490,8 +490,8 @@ parse_block_header(file_pair *pair, const lzma_index_iter *iter,
+ 
+ 		if (filters[i].id == LZMA_FILTER_LZMA2
+ 				&& iter->block.uncompressed_size == 0
+-				&& xfi->min_version < 50000032U)
+-			xfi->min_version = 50000032U;
++				&& xfi->min_version < 50000022U)
++			xfi->min_version = 50000022U;
+ 	}
+ 
+ 	// Convert the filter chain to human readable form.
+-- 
+1.7.9.6 (Apple Git-31.1)
+
diff --git a/debian/xz-utils.README.Debian b/debian/xz-utils.README.Debian
index 56444fd..180be4c 100644
--- a/debian/xz-utils.README.Debian
+++ b/debian/xz-utils.README.Debian
@@ -35,6 +35,19 @@
   process image.  Likewise when linked statically.
   (See bug #649522.)
 
+man-date, man-xz-lvv-minver (from upstream)
+  Document the "Minimum version required to decompress" field of
+  "xz --robot -v -v --list" output.
+
+xz-lvv-empty-block-minver (from upstream)
+  Fix the version number printed by "xz -lvv" for files with Blocks
+  of zero uncompressed_size: the decoder bug preventing reading such
+  files was fixed in xz 5.0.2, not 5.0.3.
+
+decoder-check-first-0x00 (from upstream)
+  Check that the first byte of range encoded data is zero to catch
+  broken files sooner.
+
 LZMA Utils compatibility
 ------------------------
 
diff --git a/src/liblzma/lzma/lzma_decoder.c b/src/liblzma/lzma/lzma_decoder.c
index d61b7de..b6f1b6a 100644
--- a/src/liblzma/lzma/lzma_decoder.c
+++ b/src/liblzma/lzma/lzma_decoder.c
@@ -289,8 +289,12 @@
 	// Initialization //
 	////////////////////
 
-	if (!rc_read_init(&coder->rc, in, in_pos, in_size))
-		return LZMA_OK;
+	{
+		const lzma_ret ret = rc_read_init(
+				&coder->rc, in, in_pos, in_size);
+		if (ret != LZMA_STREAM_END)
+			return ret;
+	}
 
 	///////////////
 	// Variables //
diff --git a/src/liblzma/rangecoder/range_decoder.h b/src/liblzma/rangecoder/range_decoder.h
index fb96180..e0b051f 100644
--- a/src/liblzma/rangecoder/range_decoder.h
+++ b/src/liblzma/rangecoder/range_decoder.h
@@ -25,20 +25,26 @@
 
 
 /// Reads the first five bytes to initialize the range decoder.
-static inline bool
+static inline lzma_ret
 rc_read_init(lzma_range_decoder *rc, const uint8_t *restrict in,
 		size_t *restrict in_pos, size_t in_size)
 {
 	while (rc->init_bytes_left > 0) {
 		if (*in_pos == in_size)
-			return false;
+			return LZMA_OK;
+
+		// The first byte is always 0x00. It could have been omitted
+		// in LZMA2 but it wasn't, so one byte is wasted in every
+		// LZMA2 chunk.
+		if (rc->init_bytes_left == 5 && in[*in_pos] != 0x00)
+			return LZMA_DATA_ERROR;
 
 		rc->code = (rc->code << 8) | in[*in_pos];
 		++*in_pos;
 		--rc->init_bytes_left;
 	}
 
-	return true;
+	return LZMA_STREAM_END;
 }
 
 
diff --git a/src/xz/list.c b/src/xz/list.c
index e71fbe2..a9e0adb 100644
--- a/src/xz/list.c
+++ b/src/xz/list.c
@@ -482,7 +482,7 @@
 	// Determine the minimum XZ Utils version that supports this Block.
 	//
 	// Currently the only thing that 5.0.0 doesn't support is empty
-	// LZMA2 Block. This bug was fixed in 5.0.3.
+	// LZMA2 Block. This decoder bug was fixed in 5.0.2.
 	{
 		size_t i = 0;
 		while (filters[i + 1].id != LZMA_VLI_UNKNOWN)
@@ -490,8 +490,8 @@
 
 		if (filters[i].id == LZMA_FILTER_LZMA2
 				&& iter->block.uncompressed_size == 0
-				&& xfi->min_version < 50000032U)
-			xfi->min_version = 50000032U;
+				&& xfi->min_version < 50000022U)
+			xfi->min_version = 50000022U;
 	}
 
 	// Convert the filter chain to human readable form.
diff --git a/src/xz/xz.1 b/src/xz/xz.1
index 57b9f6b..0952f2d 100644
--- a/src/xz/xz.1
+++ b/src/xz/xz.1
@@ -5,7 +5,7 @@
 .\" This file has been put into the public domain.
 .\" You can do whatever you want with this file.
 .\"
-.TH XZ 1 "2011-04-11" "Tukaani" "XZ Utils"
+.TH XZ 1 "2012-07-01" "Tukaani" "XZ Utils"
 .
 .SH NAME
 xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files
@@ -1883,6 +1883,14 @@
 .B no
 indicating if all block headers have both compressed size and
 uncompressed size stored in them
+.PP
+.I Since
+.B xz
+.I 5.1.2alpha:
+.IP 4. 4
+Minimum
+.B xz
+version required to decompress the file
 .RE
 .PD
 .PP
@@ -1933,6 +1941,14 @@
 .B no
 indicating if all block headers have both compressed size and
 uncompressed size stored in them
+.PP
+.I Since
+.B xz
+.I 5.1.2alpha:
+.IP 12. 4
+Minimum
+.B xz
+version required to decompress the file
 .RE
 .PD
 .PP