svn commit: trunk/busybox/archival

vda at busybox.net vda at busybox.net
Sat Jul 26 17:32:41 UTC 2008


Author: vda
Date: 2008-07-26 10:32:41 -0700 (Sat, 26 Jul 2008)
New Revision: 22954

Log:
unzip: move check for unsupported zip features to better place



Modified:
   trunk/busybox/archival/unzip.c


Changeset:
Modified: trunk/busybox/archival/unzip.c
===================================================================
--- trunk/busybox/archival/unzip.c	2008-07-26 16:50:24 UTC (rev 22953)
+++ trunk/busybox/archival/unzip.c	2008-07-26 17:32:41 UTC (rev 22954)
@@ -99,12 +99,6 @@
 
 static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
 {
-	if (zip_header->formatted.flags & (0x0008|0x0001)) {
-		/* 0x0001 - encrypted */
-		/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
-		 * only from Central Directory. See unzip_doc.txt */
-		bb_error_msg_and_die("zip flags 8 and 1 are not supported");
-	}
 	if (zip_header->formatted.method == 0) {
 		/* Method 0 - stored (not compressed) */
 		off_t size = zip_header->formatted.ucmpsize;
@@ -264,10 +258,11 @@
 
 		/* Check magic number */
 		xread(src_fd, &magic, 4);
+		/* Central directory? It's at the end, so exit */
 		if (magic == ZIP_CDS_MAGIC)
 			break;
 		if (magic != ZIP_FILEHEADER_MAGIC)
-			bb_error_msg_and_die("invalid zip magic %08X", magic);
+			bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
 
 		/* Read the file header */
 		xread(src_fd, zip_header.raw, ZIP_HEADER_LEN);
@@ -275,6 +270,12 @@
 		if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
 			bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
 		}
+		if (zip_header.formatted.flags & (0x0008|0x0001)) {
+			/* 0x0001 - encrypted */
+			/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
+			 * only from Central Directory. See unzip_doc.txt */
+			bb_error_msg_and_die("zip flags 8 and 1 are not supported");
+		}
 
 		/* Read filename */
 		free(dst_fn);
@@ -331,7 +332,7 @@
 				i = 'n';
 
 			} else {  /* Extract file */
- _check_file:
+ check_file:
 				if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
 					if (errno != ENOENT) {
 						bb_perror_msg_and_die("cannot stat '%s'", dst_fn);
@@ -390,18 +391,19 @@
 			free(dst_fn);
 			dst_fn = xstrdup(key_buf);
 			chomp(dst_fn);
-			goto _check_file;
+			goto check_file;
 
 		default:
 			printf("error: invalid response [%c]\n",(char)i);
-			goto _check_file;
+			goto check_file;
 		}
 
-		/* Data descriptor section */
-		if (zip_header.formatted.flags & 4) {
-			/* skip over duplicate crc, compressed size and uncompressed size */
-			unzip_skip(src_fd, 12);
-		}
+// Looks like bug (data descriptor cannot be identified this way)
+//		/* Data descriptor section */
+//		if (zip_header.formatted.flags & 4) {
+//			/* skip over duplicate crc, compressed size and uncompressed size */
+//			unzip_skip(src_fd, 12);
+//		}
 	}
 
 	if (listing && verbose) {




More information about the busybox-cvs mailing list