On Sat, 2012-12-22 at 10:21 -0800, Jonathan Nieder wrote:
> 
> What happens if a stream ends at a buffer boundary, followed by
> padding?  Or if padding doesn't fit in the buffer, for that
> matter?
> 
> Hope that helps,

Please find attached new debdiff with fix of above mentioned issues.

Cheers,
diff -Nru busybox-1.20.0/debian/changelog busybox-1.20.0/debian/changelog
--- busybox-1.20.0/debian/changelog	2012-09-20 08:32:55.000000000 +0200
+++ busybox-1.20.0/debian/changelog	2012-12-21 21:59:39.000000000 +0100
@@ -1,3 +1,10 @@
+busybox (1:1.20.0-7.1) unstable; urgency=low
+
+  * Fix decompression of multi stream XZ compressed files
+    (Closes: Bug#bug#686502)
+
+ -- Abou Al Montacir <abou.almonta...@sfr.fr>  Thu, 21 Dec 2012 22:00:00 +0100
+
 busybox (1:1.20.0-7) unstable; urgency=low
 
   * set CONFIG_FEATURE_COPYBUF_KB from 4 to 64 for all flavours.  This
diff -Nru busybox-1.20.0/debian/patches/fix-unxz-with-multiple-streams.patch busybox-1.20.0/debian/patches/fix-unxz-with-multiple-streams.patch
--- busybox-1.20.0/debian/patches/fix-unxz-with-multiple-streams.patch	1970-01-01 01:00:00.000000000 +0100
+++ busybox-1.20.0/debian/patches/fix-unxz-with-multiple-streams.patch	2012-12-24 23:12:05.000000000 +0100
@@ -0,0 +1,74 @@
+Author: Abou Al Montacir <abou.almonta...@sfr.fr>
+Purpose: Fix decompression of multi stream XZ compressed files
+ (Closes: bug#686502)
+
+--- busybox-1.20.0/archival/libarchive/decompress_unxz.c	2012-12-24 21:21:47.000000000 +0100
++++ busybox-1.20.0/debian/build/deb/archival/libarchive/decompress_unxz.c	2012-12-24 23:10:35.000000000 +0100
+@@ -44,6 +44,7 @@
+ 	struct xz_dec *state;
+ 	unsigned char *membuf;
+ 	IF_DESKTOP(long long) int total = 0;
++	enum xz_ret r;
+ 
+ 	if (!global_crc32_table)
+ 		global_crc32_table = crc32_filltable(NULL, /*endian:*/ 0);
+@@ -59,12 +60,10 @@
+ 		strcpy((char*)membuf, HEADER_MAGIC);
+ 		iobuf.in_size = HEADER_MAGIC_SIZE;
+ 	} /* else: let xz code read & check it */
+-
+-	/* Limit memory usage to about 64 MiB. */
+-	state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024);
++	/* First stream is identical to starting a new stream after finishing decoding an old one */
++	r = XZ_STREAM_END;
+ 
+ 	while (1) {
+-		enum xz_ret r;
+ 
+ 		if (iobuf.in_pos == iobuf.in_size) {
+ 			int rd = safe_read(src_fd, membuf, BUFSIZ);
+@@ -73,9 +72,25 @@
+ 				total = -1;
+ 				break;
+ 			}
++			/* No more bytes in stream. Stop */
++			if (rd == 0) {
++				break;
++			}
+ 			iobuf.in_size = rd;
+ 			iobuf.in_pos = 0;
+ 		}
++		if (r == XZ_STREAM_END) {
++			/* Eat padding. Stream never starts with zeros */
++			while ((iobuf.in_pos < iobuf.in_size) && (iobuf.in[iobuf.in_pos] == 0)) {
++					iobuf.in_pos += 1;
++			}
++			/* Reached end of buffer. Fill it again from stream */
++			if (iobuf.in_pos == iobuf.in_size) {
++				continue;
++			}
++			/* Initialize decoder for new stream. Limit memory usage to about 64 MiB. */
++			state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024);
++		}
+ //		bb_error_msg(">in pos:%d size:%d out pos:%d size:%d",
+ //				iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size);
+ 		r = xz_dec_run(state, &iobuf);
+@@ -87,7 +102,9 @@
+ 			iobuf.out_pos = 0;
+ 		}
+ 		if (r == XZ_STREAM_END) {
+-			break;
++			xz_dec_end(state);
++			/* Look for any other streams */
++			continue;
+ 		}
+ 		if (r != XZ_OK && r != XZ_UNSUPPORTED_CHECK) {
+ 			bb_error_msg("corrupted data");
+@@ -95,7 +112,6 @@
+ 			break;
+ 		}
+ 	}
+-	xz_dec_end(state);
+ 	free(membuf);
+ 
+ 	return total;
diff -Nru busybox-1.20.0/debian/patches/series busybox-1.20.0/debian/patches/series
--- busybox-1.20.0/debian/patches/series	2012-09-19 22:58:00.000000000 +0200
+++ busybox-1.20.0/debian/patches/series	2012-12-20 21:54:21.000000000 +0100
@@ -25,3 +25,6 @@
 dont-force-no-alignment-for-s390.patch
 
 stop-checking-ancient-kernel-version.patch
+
+# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=686502
+fix-unxz-with-multiple-streams.patch

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to