summaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorDenis Vlasenko2007-03-03 20:06:59 +0000
committerDenis Vlasenko2007-03-03 20:06:59 +0000
commitdcbd51dd2874164b693fc7133a07714c8ea14234 (patch)
tree74675981e9ef16a40b0f258c0aa173b164393682 /archival
parent19c238bc909d1e06a6bc70fe5f74124b64a4fa9d (diff)
downloadbusybox-dcbd51dd2874164b693fc7133a07714c8ea14234.zip
busybox-dcbd51dd2874164b693fc7133a07714c8ea14234.tar.gz
tar: handle tarfiles with (broken) checksums a-la Sun.
Diffstat (limited to 'archival')
-rw-r--r--archival/libunarchive/get_header_tar.c19
-rw-r--r--archival/tar.c3
2 files changed, 16 insertions, 6 deletions
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index 622f09f..a965918 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -69,7 +69,7 @@ char get_header_tar(archive_handle_t *archive_handle)
char padding[12]; /* 500-512 */
} tar;
char *cp;
- int sum, i;
+ int i, sum_u, sum_s, sum;
int parse_names;
if (sizeof(tar) != 512)
@@ -110,16 +110,23 @@ char get_header_tar(archive_handle_t *archive_handle)
#endif
bb_error_msg_and_die("invalid tar magic");
}
- /* Do checksum on headers */
- sum = ' ' * sizeof(tar.chksum);
+
+ /* Do checksum on headers.
+ * POSIX says that checksum is done on unsigned bytes, but
+ * Sun and HP-UX fucked it up... more details in
+ * GNU tar source. */
+ sum_s = sum_u = ' ' * sizeof(tar.chksum);
for (i = 0; i < 148 ; i++) {
- sum += ((char*)&tar)[i];
+ sum_u += ((unsigned char*)&tar)[i];
+ sum_s += ((signed char*)&tar)[i];
}
for (i = 156; i < 512 ; i++) {
- sum += ((char*)&tar)[i];
+ sum_u += ((unsigned char*)&tar)[i];
+ sum_s += ((signed char*)&tar)[i];
}
/* This field does not need special treatment (getOctal) */
- if (sum != xstrtoul(tar.chksum, 8)) {
+ sum = xstrtoul(tar.chksum, 8);
+ if (sum_u != sum && sum_s != sum) {
bb_error_msg_and_die("invalid tar header checksum");
}
diff --git a/archival/tar.c b/archival/tar.c
index 1cdae29..992128e 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -173,6 +173,9 @@ static void putOctal(char *cp, int len, off_t value)
static void chksum_and_xwrite(int fd, struct TarHeader* hp)
{
+ /* POSIX says that checksum is done on unsigned bytes
+ * (Sun and HP-UX fucked it up... more details in
+ * GNU tar source) */
const unsigned char *cp;
int chksum, size;