Update XZ Utils to 5.0.5.

Information about this release from README.chromium:

--
Name: XZ Utils
URL: http://tukaani.org/xz/
Source URL: http://git.tukaani.org/xz.git
Version: 5.0.5 (git tag v5.0.5, a1bfda3214ed4a39a28fe609364be133c9f0f200,
         2013-06-30 19:55:49 +0300)
License: Public domain/license grant, LGPL 2.1, GPL 2, GPL 3

Description:
XZ Utils is general-purpose data compression software implementing the
modified Lempel-Ziv-Markov chain algorithm (LZMA2).

Local Modifications:
 - None.
--

From NEWS:

--
5.0.5 (2013-06-30)

    * lzmadec and liblzma's lzma_alone_decoder(): Support decompressing
      .lzma files that have less common settings in the headers
      (dictionary size other than 2^n or 2^n + 2^(n-1), or uncompressed
      size greater than 256 GiB). The limitations existed to avoid false
      positives when detecting .lzma files. The lc + lp <= 4 limitation
      still remains since liblzma's LZMA decoder has that limitation.

      NOTE: xz's .lzma support or liblzma's lzma_auto_decoder() are NOT
      affected by this change. They still consider uncommon .lzma headers
      as not being in the .lzma format. Changing this would give way too
      many false positives.

    * xz:

        - Interaction of preset and custom filter chain options was
          made less illogical. This affects only certain less typical
          uses cases so few people are expected to notice this change.

          Now when a custom filter chain option (e.g. --lzma2) is
          specified, all preset options (-0 ... -9, -e) earlier are on
          the command line are completely forgotten. Similarly, when
          a preset option is specified, all custom filter chain options
          earlier on the command line are completely forgotten.

          Example 1: "xz -9 --lzma2=preset=5 -e" is equivalent to "xz -e"
          which is equivalent to "xz -6e". Earlier -e didn't put xz back
          into preset mode and thus the example command was equivalent
          to "xz --lzma2=preset=5".

          Example 2: "xz -9e --lzma2=preset=5 -7" is equivalent to
          "xz -7". Earlier a custom filter chain option didn't make
          xz forget the -e option so the example was equivalent to
          "xz -7e".

        - Fixes and improvements to error handling.

        - Various fixes to the man page.

    * xzless: Fixed to work with "less" versions 448 and later.

    * xzgrep: Made -h an alias for --no-filename.

    * Include the previously missing debug/translation.bash which can
      be useful for translators.

    * Include a build script for Mac OS X. This has been in the Git
      repository since 2010 but due to a mistake in Makefile.am the
      script hasn't been included in a release tarball before.
--

R=avi@chromium.org

Review URL: https://codereview.chromium.org/62403002

git-svn-id: http://src.chromium.org/svn/trunk/deps/third_party/xz@233311 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
diff --git a/Makefile.am b/Makefile.am
index 97553fa..8aa6dfc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -47,6 +47,7 @@
 	extra \
 	dos \
 	windows \
+	macosx \
 	autogen.sh \
 	Doxyfile.in \
 	COPYING.GPLv2 \
diff --git a/NEWS b/NEWS
index 4420b6a..b4f55fc 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,58 @@
 XZ Utils Release Notes
 ======================
 
+5.0.5 (2013-06-30)
+
+    * lzmadec and liblzma's lzma_alone_decoder(): Support decompressing
+      .lzma files that have less common settings in the headers
+      (dictionary size other than 2^n or 2^n + 2^(n-1), or uncompressed
+      size greater than 256 GiB). The limitations existed to avoid false
+      positives when detecting .lzma files. The lc + lp <= 4 limitation
+      still remains since liblzma's LZMA decoder has that limitation.
+
+      NOTE: xz's .lzma support or liblzma's lzma_auto_decoder() are NOT
+      affected by this change. They still consider uncommon .lzma headers
+      as not being in the .lzma format. Changing this would give way too
+      many false positives.
+
+    * xz:
+
+        - Interaction of preset and custom filter chain options was
+          made less illogical. This affects only certain less typical
+          uses cases so few people are expected to notice this change.
+
+          Now when a custom filter chain option (e.g. --lzma2) is
+          specified, all preset options (-0 ... -9, -e) earlier are on
+          the command line are completely forgotten. Similarly, when
+          a preset option is specified, all custom filter chain options
+          earlier on the command line are completely forgotten.
+
+          Example 1: "xz -9 --lzma2=preset=5 -e" is equivalent to "xz -e"
+          which is equivalent to "xz -6e". Earlier -e didn't put xz back
+          into preset mode and thus the example command was equivalent
+          to "xz --lzma2=preset=5".
+
+          Example 2: "xz -9e --lzma2=preset=5 -7" is equivalent to
+          "xz -7". Earlier a custom filter chain option didn't make
+          xz forget the -e option so the example was equivalent to
+          "xz -7e".
+
+        - Fixes and improvements to error handling.
+
+        - Various fixes to the man page.
+
+    * xzless: Fixed to work with "less" versions 448 and later.
+
+    * xzgrep: Made -h an alias for --no-filename.
+
+    * Include the previously missing debug/translation.bash which can
+      be useful for translators.
+
+    * Include a build script for Mac OS X. This has been in the Git
+      repository since 2010 but due to a mistake in Makefile.am the
+      script hasn't been included in a release tarball before.
+
+
 5.0.4 (2012-06-22)
 
     * liblzma:
diff --git a/README b/README
index 1b02f05..ab8aadf 100644
--- a/README
+++ b/README
@@ -210,8 +210,8 @@
         # <Edit the .po file in the po directory.>
         make -C po update-po
         make install
-        bash debug/translations.bash | less
-        bash debug/translations.bash | less -S  # For --list outputs
+        bash debug/translation.bash | less
+        bash debug/translation.bash | less -S  # For --list outputs
 
     Repeat the above as needed (no need to re-run configure though).
 
diff --git a/THANKS b/THANKS
index b13503e..36b2e74 100644
--- a/THANKS
+++ b/THANKS
@@ -6,6 +6,7 @@
 has been important. :-) In alphabetical order:
   - Mark Adler
   - H. Peter Anvin
+  - Jeff Bastian
   - Nelson H. F. Beebe
   - Karl Berry
   - Anders F. Björklund
@@ -47,6 +48,7 @@
   - Bela Lubkin
   - Gregory Margo
   - Jim Meyering
+  - Conley Moorhous
   - Rafał Mużyło
   - Adrien Nader
   - Hongbo Ni
@@ -58,8 +60,10 @@
   - Diego Elio Pettenò
   - Elbert Pol
   - Mikko Pouru
+  - Pavel Raiskup
   - Robert Readman
   - Bernhard Reutner-Fischer
+  - Eric S. Raymond
   - Cristian Rodríguez
   - Christian von Roques
   - Jukka Salmi
diff --git a/configure.ac b/configure.ac
index f0ccef9..305c858 100644
--- a/configure.ac
+++ b/configure.ac
@@ -416,7 +416,9 @@
 echo
 echo "Initializing Automake:"
 
-AM_INIT_AUTOMAKE([1.10 foreign tar-v7 filename-length-max=99])
+# Automake 1.10 should still be enough but you need to omit serial-tests.
+dnl AM_INIT_AUTOMAKE([1.10 foreign tar-v7 filename-length-max=99])
+AM_INIT_AUTOMAKE([1.12 foreign tar-v7 filename-length-max=99 serial-tests])
 AC_PROG_LN_S
 
 AC_PROG_CC_C99
@@ -460,7 +462,7 @@
 
 echo
 echo "Initializing gettext:"
-AM_GNU_GETTEXT_VERSION([0.16.1])
+AM_GNU_GETTEXT_VERSION([0.18])
 AM_GNU_GETTEXT([external])
 
 ###############################################################################
@@ -498,7 +500,7 @@
 AC_CHECK_SIZEOF([size_t])
 
 # The command line tool can copy high resolution timestamps if such
-# information is availabe in struct stat. Otherwise one second accuracy
+# information is available in struct stat. Otherwise one second accuracy
 # is used.
 AC_CHECK_MEMBERS([
 	struct stat.st_atim.tv_nsec,
@@ -560,6 +562,7 @@
 	for NEW_FLAG in \
 			-Wall \
 			-Wextra \
+			-Wvla \
 			-Wformat=2 \
 			-Winit-self \
 			-Wmissing-include-dirs \
diff --git a/debug/Makefile.am b/debug/Makefile.am
index 45b4b7f..9026fd9 100644
--- a/debug/Makefile.am
+++ b/debug/Makefile.am
@@ -5,6 +5,9 @@
 ## You can do whatever you want with this file.
 ##
 
+EXTRA_DIST = \
+	translation.bash
+
 noinst_PROGRAMS = \
 	repeat \
 	sync_flush \
diff --git a/debug/README b/debug/README
index 749610d..d42b272 100644
--- a/debug/README
+++ b/debug/README
@@ -3,7 +3,7 @@
 -----------
 
     This directory contains a few tiny programs that may be helpful when
-    debugging LZMA Utils.
+    debugging XZ Utils.
 
     These tools are not meant to be installed. Often one needs to edit
     the source code a little to make the programs do the wanted things.
diff --git a/src/liblzma/Makefile.am b/src/liblzma/Makefile.am
index 16e8edd..0529ff8 100644
--- a/src/liblzma/Makefile.am
+++ b/src/liblzma/Makefile.am
@@ -24,7 +24,7 @@
 	-I$(top_srcdir)/src/liblzma/simple \
 	-I$(top_srcdir)/src/common \
 	-DTUKLIB_SYMBOL_PREFIX=lzma_
-liblzma_la_LDFLAGS = -no-undefined -version-info 5:4:0
+liblzma_la_LDFLAGS = -no-undefined -version-info 5:5:0
 
 include $(srcdir)/common/Makefile.inc
 include $(srcdir)/check/Makefile.inc
diff --git a/src/liblzma/api/lzma/version.h b/src/liblzma/api/lzma/version.h
index 629e8e1..66e9396 100644
--- a/src/liblzma/api/lzma/version.h
+++ b/src/liblzma/api/lzma/version.h
@@ -22,7 +22,7 @@
  */
 #define LZMA_VERSION_MAJOR 5
 #define LZMA_VERSION_MINOR 0
-#define LZMA_VERSION_PATCH 4
+#define LZMA_VERSION_PATCH 5
 #define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE
 
 #ifndef LZMA_VERSION_COMMIT
diff --git a/src/liblzma/check/sha256.c b/src/liblzma/check/sha256.c
index 04231db..23bda92 100644
--- a/src/liblzma/check/sha256.c
+++ b/src/liblzma/check/sha256.c
@@ -6,7 +6,6 @@
 /// \todo       Crypto++ has x86 ASM optimizations. They use SSE so if they
 ///             are imported to liblzma, SSE instructions need to be used
 ///             conditionally to keep the code working on older boxes.
-///             We could also support using some external libary for SHA-256.
 //
 //  This code is based on the code found from 7-Zip, which has a modified
 //  version of the SHA-256 found from Crypto++ <http://www.cryptopp.com/>.
diff --git a/src/liblzma/common/alone_decoder.c b/src/liblzma/common/alone_decoder.c
index 678c79e..c25112e 100644
--- a/src/liblzma/common/alone_decoder.c
+++ b/src/liblzma/common/alone_decoder.c
@@ -26,6 +26,11 @@
 		SEQ_CODE,
 	} sequence;
 
+	/// If true, reject files that are unlikely to be .lzma files.
+	/// If false, more non-.lzma files get accepted and will give
+	/// LZMA_DATA_ERROR either immediately or after a few output bytes.
+	bool picky;
+
 	/// Position in the header fields
 	size_t pos;
 
@@ -68,13 +73,13 @@
 				|= (size_t)(in[*in_pos]) << (coder->pos * 8);
 
 		if (++coder->pos == 4) {
-			if (coder->options.dict_size != UINT32_MAX) {
+			if (coder->picky && coder->options.dict_size
+					!= UINT32_MAX) {
 				// A hack to ditch tons of false positives:
 				// We allow only dictionary sizes that are
 				// 2^n or 2^n + 2^(n-1). LZMA_Alone created
 				// only files with 2^n, but accepts any
-				// dictionary size. If someone complains, this
-				// will be reconsidered.
+				// dictionary size.
 				uint32_t d = coder->options.dict_size - 1;
 				d |= d >> 2;
 				d |= d >> 3;
@@ -103,9 +108,9 @@
 
 		// Another hack to ditch false positives: Assume that
 		// if the uncompressed size is known, it must be less
-		// than 256 GiB. Again, if someone complains, this
-		// will be reconsidered.
-		if (coder->uncompressed_size != LZMA_VLI_UNKNOWN
+		// than 256 GiB.
+		if (coder->picky
+				&& coder->uncompressed_size != LZMA_VLI_UNKNOWN
 				&& coder->uncompressed_size
 					>= (LZMA_VLI_C(1) << 38))
 			return LZMA_FORMAT_ERROR;
@@ -189,7 +194,7 @@
 
 extern lzma_ret
 lzma_alone_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
-		uint64_t memlimit)
+		uint64_t memlimit, bool picky)
 {
 	lzma_next_coder_init(&lzma_alone_decoder_init, next, allocator);
 
@@ -208,6 +213,7 @@
 	}
 
 	next->coder->sequence = SEQ_PROPERTIES;
+	next->coder->picky = picky;
 	next->coder->pos = 0;
 	next->coder->options.dict_size = 0;
 	next->coder->options.preset_dict = NULL;
@@ -223,7 +229,7 @@
 extern LZMA_API(lzma_ret)
 lzma_alone_decoder(lzma_stream *strm, uint64_t memlimit)
 {
-	lzma_next_strm_init(lzma_alone_decoder_init, strm, memlimit);
+	lzma_next_strm_init(lzma_alone_decoder_init, strm, memlimit, false);
 
 	strm->internal->supported_actions[LZMA_RUN] = true;
 	strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/src/liblzma/common/alone_decoder.h b/src/liblzma/common/alone_decoder.h
index 70d0d2a..f666fc3 100644
--- a/src/liblzma/common/alone_decoder.h
+++ b/src/liblzma/common/alone_decoder.h
@@ -16,7 +16,8 @@
 #include "common.h"
 
 
-extern lzma_ret lzma_alone_decoder_init(lzma_next_coder *next,
-		lzma_allocator *allocator, uint64_t memlimit);
+extern lzma_ret lzma_alone_decoder_init(
+		lzma_next_coder *next, lzma_allocator *allocator,
+		uint64_t memlimit, bool picky);
 
 #endif
diff --git a/src/liblzma/common/auto_decoder.c b/src/liblzma/common/auto_decoder.c
index ae6c3e7..35c895f 100644
--- a/src/liblzma/common/auto_decoder.c
+++ b/src/liblzma/common/auto_decoder.c
@@ -54,7 +54,7 @@
 					coder->memlimit, coder->flags));
 		} else {
 			return_if_error(lzma_alone_decoder_init(&coder->next,
-					allocator, coder->memlimit));
+					allocator, coder->memlimit, true));
 
 			// If the application wants to know about missing
 			// integrity check or about the check in general, we
diff --git a/src/lzmainfo/lzmainfo.1 b/src/lzmainfo/lzmainfo.1
index f2b93b4..ce38eee 100644
--- a/src/lzmainfo/lzmainfo.1
+++ b/src/lzmainfo/lzmainfo.1
@@ -4,14 +4,14 @@
 .\" This file has been put into the public domain.
 .\" You can do whatever you want with this file.
 .\"
-.TH LZMAINFO 1 "2010-09-27" "Tukaani" "XZ Utils"
+.TH LZMAINFO 1 "2013-06-30" "Tukaani" "XZ Utils"
 .SH NAME
 lzmainfo \- show information stored in the .lzma file header
 .SH SYNOPSIS
 .B lzmainfo
 .RB [ \-\-help ]
 .RB [ \-\-version ]
-.RI [ file ]...
+.RI [ file... ]
 .SH DESCRIPTION
 .B lzmainfo
 shows information stored in the
diff --git a/src/scripts/xzgrep.in b/src/scripts/xzgrep.in
index 515b516..2bfce19 100644
--- a/src/scripts/xzgrep.in
+++ b/src/scripts/xzgrep.in
@@ -109,7 +109,7 @@
     files_with_matches=1;;
   (-L | --files-witho*)
     files_without_matches=1;;
-  (--no-f*)
+  (-h | --no-f*)
     no_filename=1;;
   (-V | --v | --ve | --ver | --vers | --versi | --versio | --version)
     echo "$version" || exit 2
diff --git a/src/scripts/xzless.in b/src/scripts/xzless.in
index a3da697..288dd87 100644
--- a/src/scripts/xzless.in
+++ b/src/scripts/xzless.in
@@ -46,7 +46,7 @@
 	LESSMETACHARS="$space$tab$nl'"';*?"()<>[|&^`#\$%=~'
 fi
 
-if test "$(less -V | { read ver && echo ${ver#less }; })" -ge 429; then
+if test "$(less -V | { read less ver re && echo ${ver}; })" -ge 429; then
 	# less 429 or later: LESSOPEN pipe will be used on
 	# standard input if $LESSOPEN begins with |-.
 	LESSOPEN="|-$xz -cdfq -- %s"
diff --git a/src/scripts/xzmore.1 b/src/scripts/xzmore.1
index 30dad68..9613974 100644
--- a/src/scripts/xzmore.1
+++ b/src/scripts/xzmore.1
@@ -4,15 +4,15 @@
 .\"
 .\" License: GNU GPLv2+
 .\"
-.TH XZMORE 1 "2010-09-27" "Tukaani" "XZ Utils"
+.TH XZMORE 1 "2013-06-30" "Tukaani" "XZ Utils"
 .SH NAME
 xzmore, lzmore \- view xz or lzma compressed (text) files
 .SH SYNOPSIS
 .B xzmore
-.RI [ "filename ..." ]
+.RI [ file... ]
 .br
 .B lzmore
-.RI [ "filename ..." ]
+.RI [ file... ]
 .SH DESCRIPTION
 .B  xzmore
 is a filter which allows examination of
diff --git a/src/xz/coder.c b/src/xz/coder.c
index 69b1225..e0867e2 100644
--- a/src/xz/coder.c
+++ b/src/xz/coder.c
@@ -37,15 +37,10 @@
 static io_buf out_buf;
 
 /// Number of filters. Zero indicates that we are using a preset.
-static size_t filters_count = 0;
+static uint32_t filters_count = 0;
 
 /// Number of the preset (0-9)
-static size_t preset_number = 6;
-
-/// If a preset is used (no custom filter chain) and preset_extreme is true,
-/// a significantly slower compression is used to achieve slightly better
-/// compression ratio.
-static bool preset_extreme = false;
+static uint32_t preset_number = LZMA_PRESET_DEFAULT;
 
 /// Integrity check type
 static lzma_check check;
@@ -63,11 +58,9 @@
 }
 
 
-extern void
-coder_set_preset(size_t new_preset)
+static void
+forget_filter_chain(void)
 {
-	preset_number = new_preset;
-
 	// Setting a preset makes us forget a possibly defined custom
 	// filter chain.
 	while (filters_count > 0) {
@@ -81,9 +74,20 @@
 
 
 extern void
+coder_set_preset(uint32_t new_preset)
+{
+	preset_number &= ~LZMA_PRESET_LEVEL_MASK;
+	preset_number |= new_preset;
+	forget_filter_chain();
+	return;
+}
+
+
+extern void
 coder_set_extreme(void)
 {
-	preset_extreme = true;
+	preset_number |= LZMA_PRESET_EXTREME;
+	forget_filter_chain();
 	return;
 }
 
@@ -98,6 +102,12 @@
 	filters[filters_count].options = options;
 	++filters_count;
 
+	// Setting a custom filter chain makes us forget the preset options.
+	// This makes a difference if one specifies e.g. "xz -9 --lzma2 -e"
+	// where the custom filter chain resets the preset level back to
+	// the default 6, making the example equivalent to "xz -6e".
+	preset_number = LZMA_PRESET_DEFAULT;
+
 	return;
 }
 
@@ -134,9 +144,6 @@
 		}
 
 		// Get the preset for LZMA1 or LZMA2.
-		if (preset_extreme)
-			preset_number |= LZMA_PRESET_EXTREME;
-
 		if (lzma_lzma_preset(&opt_lzma, preset_number))
 			message_bug();
 
diff --git a/src/xz/coder.h b/src/xz/coder.h
index 4626466..2d3add9 100644
--- a/src/xz/coder.h
+++ b/src/xz/coder.h
@@ -46,7 +46,7 @@
 extern void coder_set_check(lzma_check check);
 
 /// Set preset number
-extern void coder_set_preset(size_t new_preset);
+extern void coder_set_preset(uint32_t new_preset);
 
 /// Enable extreme mode
 extern void coder_set_extreme(void);
diff --git a/src/xz/file_io.c b/src/xz/file_io.c
index f9b7f30..871a099 100644
--- a/src/xz/file_io.c
+++ b/src/xz/file_io.c
@@ -41,9 +41,10 @@
 static bool try_sparse = true;
 
 #ifndef TUKLIB_DOSLIKE
-/// File status flags of standard output. This is used by io_open_dest()
-/// and io_close_dest().
-static int stdout_flags = 0;
+/// Original file status flags of standard output. This is used by
+/// io_open_dest() and io_close_dest() to save and restore the flags.
+static int stdout_flags;
+static bool restore_stdout_flags = false;
 #endif
 
 
@@ -397,10 +398,6 @@
 			was_symlink = true;
 
 #	elif defined(__NetBSD__)
-		// As of 2010-09-05, NetBSD doesn't document what errno is
-		// used with O_NOFOLLOW. It is EFTYPE though, and I
-		// understood that is very unlikely to change even though
-		// it is undocumented.
 		if (errno == EFTYPE)
 			was_symlink = true;
 
@@ -441,7 +438,7 @@
 
 		flags &= ~O_NONBLOCK;
 
-		if (fcntl(pair->src_fd, F_SETFL, flags))
+		if (fcntl(pair->src_fd, F_SETFL, flags) == -1)
 			goto error_msg;
 	}
 #endif
@@ -634,11 +631,11 @@
 			if (!S_ISREG(pair->dest_st.st_mode))
 				return false;
 
-			const int flags = fcntl(STDOUT_FILENO, F_GETFL);
-			if (flags == -1)
+			stdout_flags = fcntl(STDOUT_FILENO, F_GETFL);
+			if (stdout_flags == -1)
 				return false;
 
-			if (flags & O_APPEND) {
+			if (stdout_flags & O_APPEND) {
 				// Creating a sparse file is not possible
 				// when O_APPEND is active (it's used by
 				// shell's >> redirection). As I understand
@@ -657,12 +654,14 @@
 					return false;
 
 				if (fcntl(STDOUT_FILENO, F_SETFL,
-						stdout_flags & ~O_APPEND))
+						stdout_flags & ~O_APPEND)
+						== -1)
 					return false;
 
-				// Remember the flags so that io_close_dest()
-				// can restore them.
-				stdout_flags = flags;
+				// Disabling O_APPEND succeeded. Mark
+				// that the flags should be restored
+				// in io_close_dest().
+				restore_stdout_flags = true;
 
 			} else if (lseek(STDOUT_FILENO, 0, SEEK_CUR)
 					!= pair->dest_st.st_size) {
@@ -703,13 +702,12 @@
 {
 #ifndef TUKLIB_DOSLIKE
 	// If io_open_dest() has disabled O_APPEND, restore it here.
-	if (stdout_flags != 0) {
+	if (restore_stdout_flags) {
 		assert(pair->dest_fd == STDOUT_FILENO);
 
-		const int fail = fcntl(STDOUT_FILENO, F_SETFL, stdout_flags);
-		stdout_flags = 0;
+		restore_stdout_flags = false;
 
-		if (fail) {
+		if (fcntl(STDOUT_FILENO, F_SETFL, stdout_flags) == -1) {
 			message_error(_("Error restoring the O_APPEND flag "
 					"to standard output: %s"),
 					strerror(errno));
@@ -882,7 +880,7 @@
 		if (amount == -1) {
 			if (errno == EINTR) {
 				if (user_abort)
-					return -1;
+					return true;
 
 				continue;
 			}
diff --git a/src/xz/list.c b/src/xz/list.c
index 98307eb..0e73d51 100644
--- a/src/xz/list.c
+++ b/src/xz/list.c
@@ -203,6 +203,20 @@
 			goto error;
 		}
 
+		// Check that the Stream Footer doesn't specify something
+		// that we don't support. This can only happen if the xz
+		// version is older than liblzma and liblzma supports
+		// something new.
+		//
+		// It is enough to check Stream Footer. Stream Header must
+		// match when it is compared against Stream Footer with
+		// lzma_stream_flags_compare().
+		if (footer_flags.version != 0) {
+			message_error("%s: %s", pair->src_name,
+					message_strm(LZMA_OPTIONS_ERROR));
+			goto error;
+		}
+
 		// Check that the size of the Index field looks sane.
 		lzma_vli index_size = footer_flags.backward_size;
 		if ((lzma_vli)(pos) < index_size + LZMA_STREAM_HEADER_SIZE) {
@@ -429,7 +443,19 @@
 	switch (lzma_block_compressed_size(&block,
 			iter->block.unpadded_size)) {
 	case LZMA_OK:
-		break;
+		// Validate also block.uncompressed_size if it is present.
+		// If it isn't present, there's no need to set it since
+		// we aren't going to actually decompress the Block; if
+		// we were decompressing, then we should set it so that
+		// the Block decoder could validate the Uncompressed Size
+		// that was stored in the Index.
+		if (block.uncompressed_size == LZMA_VLI_UNKNOWN
+				|| block.uncompressed_size
+					== iter->block.uncompressed_size)
+			break;
+
+		// If the above fails, the file is corrupt so
+		// LZMA_DATA_ERROR is a good error code.
 
 	case LZMA_DATA_ERROR:
 		// Free the memory allocated by lzma_block_header_decode().
diff --git a/src/xz/util.c b/src/xz/util.c
index 987b443..35850f4 100644
--- a/src/xz/util.c
+++ b/src/xz/util.c
@@ -26,9 +26,19 @@
 {
 	assert(size > 0);
 
+	// Save ptr so that we can free it if realloc fails.
+	// The point is that message_fatal ends up calling stdio functions
+	// which in some libc implementations might allocate memory from
+	// the heap. Freeing ptr improves the chances that there's free
+	// memory for stdio functions if they need it.
+	void *p = ptr;
 	ptr = realloc(ptr, size);
-	if (ptr == NULL)
-		message_fatal("%s", strerror(errno));
+
+	if (ptr == NULL) {
+		const int saved_errno = errno;
+		free(p);
+		message_fatal("%s", strerror(saved_errno));
+	}
 
 	return ptr;
 }
diff --git a/src/xz/xz.1 b/src/xz/xz.1
index 8edc456..363b90c 100644
--- a/src/xz/xz.1
+++ b/src/xz/xz.1
@@ -5,16 +5,17 @@
 .\" 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 "2013-06-21" "Tukaani" "XZ Utils"
 .
 .SH NAME
 xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files
 .
 .SH SYNOPSIS
 .B xz
-.RI [ option ]...
-.RI [ file ]...
-.PP
+.RI [ option... ]
+.RI [ file... ]
+.
+.SH COMMAND ALIASES
 .B unxz
 is equivalent to
 .BR "xz \-\-decompress" .
@@ -708,7 +709,7 @@
 DecMem contains the decompressor memory requirements.
 That is, the compression settings determine
 the memory requirements of the decompressor.
-The exact decompressor memory usage is slighly more than
+The exact decompressor memory usage is slightly more than
 the LZMA2 dictionary size, but the values in the table
 have been rounded up to the next full MiB.
 .RE
@@ -897,11 +898,14 @@
 .SS "Custom compressor filter chains"
 A custom filter chain allows specifying
 the compression settings in detail instead of relying on
-the settings associated to the preset levels.
+the settings associated to the presets.
 When a custom filter chain is specified,
-the compression preset level options
-(\fB\-0\fR ... \fB\-9\fR and \fB\-\-extreme\fR) are
-silently ignored.
+preset options (\fB\-0\fR ... \fB\-9\fR and \fB\-\-extreme\fR)
+earlier on the command line are forgotten.
+If a preset option is specified
+after one or more custom filter chain options,
+the new preset takes effect and
+the custom filter chain options specified earlier are forgotten.
 .PP
 A filter chain is comparable to piping on the command line.
 When compressing, the uncompressed input goes to the first filter,
@@ -934,6 +938,15 @@
 are ignored.
 Every option has a default value, so you need to
 specify only those you want to change.
+.PP
+To see the whole filter chain and
+.IR options ,
+use
+.B "xz \-vv"
+(that is, use
+.B \-\-verbose
+twice).
+This works also for viewing the filter chain options used by presets.
 .TP
 \fB\-\-lzma1\fR[\fB=\fIoptions\fR]
 .PD 0
@@ -976,13 +989,12 @@
 .BR e ,
 which matches
 .BR \-\-extreme .
-The default
-.I preset
-is
-.BR 6 ,
-from which the default values for the rest of the LZMA1 or LZMA2
+If no
+.B preset
+is specified, the default values of LZMA1 or LZMA2
 .I options
-are taken.
+are taken from the preset
+.BR 6 .
 .TP
 .BI dict= size
 Dictionary (history buffer)
@@ -1578,7 +1590,7 @@
 .BR \-\-info\-memory ,
 and
 .BR \-\-list .
-It will be supported for normal compression and
+It will be supported for compression and
 decompression in the future.
 .
 .SS Version
@@ -2179,14 +2191,15 @@
 builds of the same XZ Utils version,
 if different build options are used.
 .PP
-The above means that implementing
+The above means that once
 .B \-\-rsyncable
-to create rsyncable
-.B .xz
-files is not going to happen without
-freezing a part of the encoder
-implementation, which can then be used with
-.BR \-\-rsyncable .
+has been implemented,
+the resulting files won't necessarily be rsyncable
+unless both old and new files have been compressed
+with the same xz version.
+This problem can be fixed if a part of the encoder
+implementation is frozen to keep rsyncable output
+stable across xz versions.
 .
 .SS "Embedded .xz decompressors"
 Embedded
diff --git a/src/xzdec/xzdec.1 b/src/xzdec/xzdec.1
index 7cc9be5..1e5ced9 100644
--- a/src/xzdec/xzdec.1
+++ b/src/xzdec/xzdec.1
@@ -4,17 +4,17 @@
 .\" This file has been put into the public domain.
 .\" You can do whatever you want with this file.
 .\"
-.TH XZDEC 1 "2010-09-27" "Tukaani" "XZ Utils"
+.TH XZDEC 1 "2013-06-30" "Tukaani" "XZ Utils"
 .SH NAME
 xzdec, lzmadec \- Small .xz and .lzma decompressors
 .SH SYNOPSIS
 .B xzdec
-.RI [ option ]...
-.RI [ file ]...
+.RI [ option... ]
+.RI [ file... ]
 .br
 .B lzmadec
-.RI [ option ]...
-.RI [ file ]...
+.RI [ option... ]
+.RI [ file... ]
 .SH DESCRIPTION
 .B xzdec
 is a liblzma-based decompression-only tool for
diff --git a/src/xzdec/xzdec.c b/src/xzdec/xzdec.c
index b7830db..5cb7530 100644
--- a/src/xzdec/xzdec.c
+++ b/src/xzdec/xzdec.c
@@ -62,13 +62,13 @@
 {
 	printf(
 "Usage: %s [OPTION]... [FILE]...\n"
-"Uncompress files in the ." TOOL_FORMAT " format to the standard output.\n"
+"Decompress files in the ." TOOL_FORMAT " format to standard output.\n"
 "\n"
-"  -c, --stdout       (ignored)\n"
-"  -d, --decompress   (ignored)\n"
-"  -k, --keep         (ignored)\n"
+"  -d, --decompress   (ignored, only decompression is supported)\n"
+"  -k, --keep         (ignored, files are never deleted)\n"
+"  -c, --stdout       (ignored, output is always written to standard output)\n"
 "  -q, --quiet        specify *twice* to suppress errors\n"
-"  -Q, --no-warn      (ignored)\n"
+"  -Q, --no-warn      (ignored, the exit status 2 is never used)\n"
 "  -h, --help         display this help and exit\n"
 "  -V, --version      display the version number and exit\n"
 "\n"
diff --git a/tests/test_block.c b/tests/test_block.c
deleted file mode 100644
index 0352dce..0000000
--- a/tests/test_block.c
+++ /dev/null
@@ -1,52 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-//
-/// \file       test_block.c
-/// \brief      Tests Block coders
-//
-//  Author:     Lasse Collin
-//
-//  This file has been put into the public domain.
-//  You can do whatever you want with this file.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include "tests.h"
-
-
-static uint8_t text[] = "Hello world!";
-static uint8_t buffer[4096];
-static lzma_options_block block_options;
-static lzma_stream strm = LZMA_STREAM_INIT;
-
-
-static void
-test1(void)
-{
-
-}
-
-
-int
-main()
-{
-	lzma_init();
-
-	block_options = (lzma_options_block){
-		.check_type = LZMA_CHECK_NONE,
-		.has_eopm = true,
-		.has_uncompressed_size_in_footer = false,
-		.has_backward_size = false,
-		.handle_padding = false,
-		.total_size = LZMA_VLI_UNKNOWN,
-		.compressed_size = LZMA_VLI_UNKNOWN,
-		.uncompressed_size = LZMA_VLI_UNKNOWN,
-		.header_size = 5,
-	};
-	block_options.filters[0].id = LZMA_VLI_UNKNOWN;
-	block_options.filters[0].options = NULL;
-
-
-	lzma_end(&strm);
-
-	return 0;
-}