Blame SOURCES/libarchive-3.1.2-rhbz-1347086.patch

58251f
From 6e06b1c89dd0d16f74894eac4cfc1327a06ee4a0 Mon Sep 17 00:00:00 2001
58251f
From: Tim Kientzle <kientzle@acm.org>
58251f
Date: Sat, 10 Jan 2015 12:24:58 -0800
58251f
Subject: [PATCH] Fix a potential crash issue discovered by Alexander
58251f
 Cherepanov:
58251f
58251f
It seems bsdtar automatically handles stacked compression. This is a
58251f
nice feature but it could be problematic when it's completely
58251f
unlimited.  Most clearly it's illustrated with quines:
58251f
58251f
$ curl -sRO http://www.maximumcompression.com/selfgz.gz
58251f
$ (ulimit -v 10000000 && bsdtar -tvf selfgz.gz)
58251f
bsdtar: Error opening archive: Can't allocate data for gzip decompression
58251f
58251f
Without ulimit, bsdtar will eat all available memory. This could also
58251f
be a problem for other applications using libarchive.
58251f
---
58251f
 Makefile.am                                      |  2 ++
58251f
 libarchive/archive_read.c                        |  7 ++--
58251f
 libarchive/test/CMakeLists.txt                   |  1 +
58251f
 libarchive/test/test_read_too_many_filters.c     | 45 ++++++++++++++++++++++++
58251f
 libarchive/test/test_read_too_many_filters.gz.uu | 15 ++++++++
58251f
 5 files changed, 68 insertions(+), 2 deletions(-)
58251f
 create mode 100644 libarchive/test/test_read_too_many_filters.c
58251f
 create mode 100644 libarchive/test/test_read_too_many_filters.gz.uu
58251f
58251f
diff --git a/Makefile.am b/Makefile.am
58251f
index 3fa2d22..d6e40a2 100644
58251f
--- a/Makefile.am
58251f
+++ b/Makefile.am
58251f
@@ -432,6 +432,7 @@ libarchive_test_SOURCES=					\
58251f
 	libarchive/test/test_read_pax_truncated.c		\
58251f
 	libarchive/test/test_read_position.c			\
58251f
 	libarchive/test/test_read_set_format.c			\
58251f
+	libarchive/test/test_read_too_many_filters.c		\
58251f
 	libarchive/test/test_read_truncated.c			\
58251f
 	libarchive/test/test_read_truncated_filter.c		\
58251f
 	libarchive/test/test_sparse_basic.c			\
58251f
@@ -693,6 +694,7 @@ libarchive_test_EXTRA_DIST=\
58251f
 	libarchive/test/test_read_splitted_rar_ab.uu			\
58251f
 	libarchive/test/test_read_splitted_rar_ac.uu			\
58251f
 	libarchive/test/test_read_splitted_rar_ad.uu			\
58251f
+	libarchive/test/test_read_too_many_filters.gz.uu		\
58251f
 	libarchive/test/test_splitted_rar_seek_support_aa.uu		\
58251f
 	libarchive/test/test_splitted_rar_seek_support_ab.uu		\
58251f
 	libarchive/test/test_splitted_rar_seek_support_ac.uu		\
58251f
diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c
58251f
index 048c316..f8dde89 100644
58251f
--- a/libarchive/archive_read.c
58251f
+++ b/libarchive/archive_read.c
58251f
@@ -544,13 +544,13 @@ archive_read_open1(struct archive *_a)
58251f
 static int
58251f
 choose_filters(struct archive_read *a)
58251f
 {
58251f
-	int number_bidders, i, bid, best_bid;
58251f
+	int number_bidders, i, bid, best_bid, n;
58251f
 	struct archive_read_filter_bidder *bidder, *best_bidder;
58251f
 	struct archive_read_filter *filter;
58251f
 	ssize_t avail;
58251f
 	int r;
58251f
 
58251f
-	for (;;) {
58251f
+	for (n = 0; n < 25; ++n) {
58251f
 		number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);
58251f
 
58251f
 		best_bid = 0;
58251f
@@ -596,6 +596,9 @@ choose_filters(struct archive_read *a)
58251f
 			return (ARCHIVE_FATAL);
58251f
 		}
58251f
 	}
58251f
+	archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
58251f
+	    "Input requires too many filters for decoding");
58251f
+	return (ARCHIVE_FATAL);
58251f
 }
58251f
 
58251f
 /*
58251f
diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt
58251f
index d2eb2c2..6ac850d 100644
58251f
--- a/libarchive/test/CMakeLists.txt
58251f
+++ b/libarchive/test/CMakeLists.txt
58251f
@@ -147,6 +147,7 @@ IF(ENABLE_TEST)
58251f
     test_read_pax_truncated.c
58251f
     test_read_position.c
58251f
     test_read_set_format.c
58251f
+    test_read_too_many_filters.c
58251f
     test_read_truncated.c
58251f
     test_read_truncated_filter.c
58251f
     test_sparse_basic.c
58251f
diff --git a/libarchive/test/test_read_too_many_filters.c b/libarchive/test/test_read_too_many_filters.c
58251f
new file mode 100644
58251f
index 0000000..37cab24
58251f
--- /dev/null
58251f
+++ b/libarchive/test/test_read_too_many_filters.c
58251f
@@ -0,0 +1,45 @@
58251f
+/*-
58251f
+ * Copyright (c) 2003-2008,2015 Tim Kientzle
58251f
+ * All rights reserved.
58251f
+ *
58251f
+ * Redistribution and use in source and binary forms, with or without
58251f
+ * modification, are permitted provided that the following conditions
58251f
+ * are met:
58251f
+ * 1. Redistributions of source code must retain the above copyright
58251f
+ *    notice, this list of conditions and the following disclaimer.
58251f
+ * 2. Redistributions in binary form must reproduce the above copyright
58251f
+ *    notice, this list of conditions and the following disclaimer in the
58251f
+ *    documentation and/or other materials provided with the distribution.
58251f
+ *
58251f
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
58251f
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58251f
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
58251f
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
58251f
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58251f
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58251f
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58251f
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58251f
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58251f
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58251f
+ */
58251f
+#include "test.h"
58251f
+
58251f
+DEFINE_TEST(test_read_too_many_filters)
58251f
+{
58251f
+	const char *name = "test_read_too_many_filters.gz";
58251f
+	struct archive *a;
58251f
+	int r;
58251f
+
58251f
+	assert((a = archive_read_new()) != NULL);
58251f
+	r = archive_read_support_filter_gzip(a);
58251f
+	if (r == ARCHIVE_WARN) {
58251f
+		skipping("gzip reading not fully supported on this platform");
58251f
+	}
58251f
+	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
58251f
+	extract_reference_file(name);
58251f
+	assertEqualIntA(a, ARCHIVE_FATAL,
58251f
+	    archive_read_open_filename(a, name, 200));
58251f
+
58251f
+	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
58251f
+	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
58251f
+}
58251f
diff --git a/libarchive/test/test_read_too_many_filters.gz.uu b/libarchive/test/test_read_too_many_filters.gz.uu
58251f
new file mode 100644
58251f
index 0000000..6bf6614
58251f
--- /dev/null
58251f
+++ b/libarchive/test/test_read_too_many_filters.gz.uu
58251f
@@ -0,0 +1,15 @@
58251f
+This is a valid gzip file that decompresses to itself, from
58251f
+  http://www.maximumcompression.com/selfgz.gz
58251f
+
58251f
+This is used in test_read_too_many_filters to try to
58251f
+crash libarchive by forcing it to spawn an unending
58251f
+list of gunzip filters.
58251f
+
58251f
+begin 644 test_read_too_many_filters.gz
58251f
+M'XL(`````````P`/`/#_'XL(`````````P`/`/#_````__\```#__X)QH5P`
58251f
+M`!X`X?\```#__P```/__@G&A7```'@#A_P```/__````__\```#__P```/__
58251f
+M````__\```#__\(FAF`!`!0`Z_\```#__P```/__PB:&8`$`%`#K_\(FAF`!
58251f
+M`!0`Z_^9(#6-B"@Q,C,T`K/`+```%`#K_P*SP"P``!0`Z_]"B"'$`````/__
58251f
+>`P!#2DTAT@```$*((<0`````__\#`$-*32'2````
58251f
+`
58251f
+end
58251f
-- 
58251f
2.7.4
58251f