[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#756462: busybox: Update deb format support



Package: busybox
Version: 1:1.22.0-6
Severity: wishlist
Tags: patch

Hi!

As part of an effort [S] to try to get as much tools to understand
the current .deb format (see deb(5)), I'm attaching a patch updating
the busybox dpkg and dpkg-deb applets against that spec.

 [S] <https://wiki.debian.org/Teams/Dpkg/DebSupport>

As those applets are only built for the busybox-static package, I've
tested that one against the test packages from the dpkg/pkg-tests.git
repository [T], which can be found in the t-deb-format directory.

  [T] <git://anonscm.debian.org/dpkg/pkg-tests.git>

I only found an issue with a control.tar.xz member, and the dpkg-deb
applet that prints a corrupted data error, but outputs the entire
control file correctly, and extracts it also correctly, so I think
this is an issue with the existing xz decoder in busybox, and as a
wild guess probably from the 0 padding in the tar archive. Here's an
excerpt from the session:

,---
$ dpkg-deb -I pkg-control-xz.deb
 new debian package, version 2.0.
 size 744 bytes: control archive=348 bytes.
     193 bytes,     7 lines      control
 Package: pkg-deb-format
 Version: 0.0-1
 Section: test
 Priority: extra
 Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
 Architecture: all
 Description: test package - deb format support
$ busybox dpkg-deb -f pkg-control-xz.deb 
Package: pkg-deb-format
Version: 0.0-1
Section: test
Priority: extra
Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
Architecture: all
Description: test package - deb format support
dpkg-deb: corrupted data
$ busybox dpkg-deb -e pkg-control-xz.deb DEBIAN
dpkg-deb: corrupted data
$ ls -l  DEBIAN/
total 4
-rw-r--r-- 1 guillem guillem 193 Jul 30 04:27 control
`---

Thanks,
Guillem
Description: Add support for latest .deb format members
 This adds support for control.tar, control.tar.xz, data.tar, data.tar.xz
 and data.tar.lzma in the dpkg and dpkg-deb applet. It also removes support
 for control.tar.bz2 which has never been supported.
 .
 This should make these applets conform to deb(5).
Author: Guillem Jover <guillem@debian.org>
Origin: vendor
Forwarded: no
Last-Update: 2014-07-30


diff --git a/archival/dpkg.c b/archival/dpkg.c
index 2893cfc..71eae66 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -1472,11 +1472,12 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
 	tar_handle->src_fd = ar_handle->src_fd;
 
 	/* We don't care about data.tar.* or debian-binary, just control.tar.* */
+	llist_add_to(&(ar_handle->accept), (char*)"control.tar");
 #if ENABLE_FEATURE_SEAMLESS_GZ
 	llist_add_to(&(ar_handle->accept), (char*)"control.tar.gz");
 #endif
-#if ENABLE_FEATURE_SEAMLESS_BZ2
-	llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2");
+#if ENABLE_FEATURE_SEAMLESS_XZ
+	llist_add_to(&(ar_handle->accept), (char*)"control.tar.xz");
 #endif
 
 	/* Assign the tar handle as a subarchive of the ar handle */
@@ -1492,12 +1493,19 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
 	tar_handle->src_fd = ar_handle->src_fd;
 
 	/* We don't care about control.tar.* or debian-binary, just data.tar.* */
+	llist_add_to(&(ar_handle->accept), (char*)"data.tar");
 #if ENABLE_FEATURE_SEAMLESS_GZ
 	llist_add_to(&(ar_handle->accept), (char*)"data.tar.gz");
 #endif
+#if ENABLE_FEATURE_SEAMLESS_XZ
+	llist_add_to(&(ar_handle->accept), (char*)"data.tar.xz");
+#endif
 #if ENABLE_FEATURE_SEAMLESS_BZ2
 	llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2");
 #endif
+#if ENABLE_FEATURE_SEAMLESS_LZMA
+	llist_add_to(&(ar_handle->accept), (char*)"data.tar.lzma");
+#endif
 
 	/* Assign the tar handle as a subarchive of the ar handle */
 	ar_handle->dpkg__sub_archive = tar_handle;
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index 13f9db9..48920f6 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -70,10 +70,16 @@ int dpkg_deb_main(int argc, char **argv)
 	ar_archive->dpkg__sub_archive = tar_archive;
 	ar_archive->filter = filter_accept_list_reassign;
 
+	llist_add_to(&ar_archive->accept, (char*)"data.tar");
+	llist_add_to(&control_tar_llist, (char*)"control.tar");
 #if ENABLE_FEATURE_SEAMLESS_GZ
 	llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
 	llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
 #endif
+#if ENABLE_FEATURE_SEAMLESS_XZ
+	llist_add_to(&ar_archive->accept, (char*)"data.tar.xz");
+	llist_add_to(&control_tar_llist, (char*)"control.tar.xz");
+#endif
 #if ENABLE_FEATURE_SEAMLESS_BZ2
 	llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2");
 	llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
diff --git a/archival/libarchive/Kbuild.src b/archival/libarchive/Kbuild.src
index 968fdf8..fda05d8 100644
--- a/archival/libarchive/Kbuild.src
+++ b/archival/libarchive/Kbuild.src
@@ -33,6 +33,7 @@ DPKG_FILES:= \
 	get_header_ar.o \
 	get_header_tar.o \
 	get_header_tar_gz.o \
+	get_header_tar_xz.o \
 	get_header_tar_bz2.o \
 	get_header_tar_lzma.o \
 
diff --git a/archival/libarchive/filter_accept_list_reassign.c b/archival/libarchive/filter_accept_list_reassign.c
index 3d19abe..bcfeb96 100644
--- a/archival/libarchive/filter_accept_list_reassign.c
+++ b/archival/libarchive/filter_accept_list_reassign.c
@@ -28,12 +28,23 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
 		name_ptr++;
 
 		/* Modify the subarchive handler based on the extension */
+		if (strcmp(name_ptr, "tar") == 0
+		) {
+			archive_handle->dpkg__action_data_subarchive = get_header_tar;
+			return EXIT_SUCCESS;
+		}
 		if (ENABLE_FEATURE_SEAMLESS_GZ
 		 && strcmp(name_ptr, "gz") == 0
 		) {
 			archive_handle->dpkg__action_data_subarchive = get_header_tar_gz;
 			return EXIT_SUCCESS;
 		}
+		if (ENABLE_FEATURE_SEAMLESS_XZ
+		 && strcmp(name_ptr, "xz") == 0
+		) {
+			archive_handle->dpkg__action_data_subarchive = get_header_tar_xz;
+			return EXIT_SUCCESS;
+		}
 		if (ENABLE_FEATURE_SEAMLESS_BZ2
 		 && strcmp(name_ptr, "bz2") == 0
 		) {
diff --git a/archival/libarchive/get_header_tar_xz.c b/archival/libarchive/get_header_tar_xz.c
new file mode 100644
index 0000000..30ac522
--- /dev/null
+++ b/archival/libarchive/get_header_tar_xz.c
@@ -0,0 +1,21 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+
+#include "libbb.h"
+#include "bb_archive.h"
+
+char FAST_FUNC get_header_tar_xz(archive_handle_t *archive_handle)
+{
+	/* Can't lseek over pipes */
+	archive_handle->seek = seek_by_read;
+
+	open_transformer_with_sig(archive_handle->src_fd, unpack_xz_stream, "unxz");
+	archive_handle->offset = 0;
+	while (get_header_tar(archive_handle) == EXIT_SUCCESS)
+		continue;
+
+	/* Can only do one file at a time */
+	return EXIT_FAILURE;
+}
diff --git a/include/bb_archive.h b/include/bb_archive.h
index b82cfd8..a356f70 100644
--- a/include/bb_archive.h
+++ b/include/bb_archive.h
@@ -182,6 +182,7 @@ char get_header_ar(archive_handle_t *archive_handle) FAST_FUNC;
 char get_header_cpio(archive_handle_t *archive_handle) FAST_FUNC;
 char get_header_tar(archive_handle_t *archive_handle) FAST_FUNC;
 char get_header_tar_gz(archive_handle_t *archive_handle) FAST_FUNC;
+char get_header_tar_xz(archive_handle_t *archive_handle) FAST_FUNC;
 char get_header_tar_bz2(archive_handle_t *archive_handle) FAST_FUNC;
 char get_header_tar_lzma(archive_handle_t *archive_handle) FAST_FUNC;
 

Reply to: