kern/160430: [patch] Add __packed to libarchive cpio metadata structs

Ian Lepore freebsd at
Sat Sep 3 16:30:11 UTC 2011

>Number:         160430
>Category:       kern
>Synopsis:       [patch] Add __packed to libarchive cpio metadata structs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 03 16:30:10 UTC 2011
>Originator:     Ian Lepore <freebsd at>
>Release:        FreeBSD 8.2-RC3 arm
FreeBSD dvb 8.2-RC3 FreeBSD 8.2-RC3 #49: Tue Feb 15 22:52:14 UTC 2011     root at revolution.hippie.lan:/usr/obj/arm/usr/src/sys/DVB  arm

Some platforms (such as ARM) pad structures to a multiple of the platform's
"natural alignment".  This causes libarchive to go into an endless loop when
processing a cpio archive on such a platform.  Adding the __packed attribute
fixes the problem.

Create a cpio archive ('newc' format) and attempt to list or extract it on ARM.

Patch attached.  This patch is well-tested; it has been in use at Symmetricom
since 2007 for our products that run on both ARM and x86 (32-bit) platforms.

--- diff.tmp begins here ---
--- archive_read_support_format_cpio.c.orig	2009-12-28 22:50:34.000000000 -0700
+++ archive_read_support_format_cpio.c	2011-09-03 09:50:07.000000000 -0600
@@ -54,7 +54,7 @@ struct cpio_bin_header {
 	unsigned char	c_mtime[4];
 	unsigned char	c_namesize[2];
 	unsigned char	c_filesize[4];
+} __packed;	/* prevent struct size padding on arm */
 struct cpio_odc_header {
 	char	c_magic[6];
@@ -68,7 +68,7 @@ struct cpio_odc_header {
 	char	c_mtime[11];
 	char	c_namesize[6];
 	char	c_filesize[11];
+} __packed;	/* prevent struct size padding on arm */
 struct cpio_newc_header {
 	char	c_magic[6];
@@ -85,7 +85,7 @@ struct cpio_newc_header {
 	char	c_rdevminor[8];
 	char	c_namesize[8];
 	char	c_crc[8];
+} __packed;	/* prevent struct size padding on arm */
 struct links_entry {
         struct links_entry      *next;
--- diff.tmp ends here ---


More information about the freebsd-bugs mailing list