diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-26 17:32:41 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-26 17:32:41 +0000 |
commit | 48a9971bd41a6ad7fc2ee52dcc885b25012b5561 (patch) | |
tree | 91a16ebe8a7d177d0c4cfdbfd3dff123805bf6cd | |
parent | c2dcb7cf63993a80208db653d1f9d39eab5a4567 (diff) | |
download | busybox-w32-48a9971bd41a6ad7fc2ee52dcc885b25012b5561.tar.gz busybox-w32-48a9971bd41a6ad7fc2ee52dcc885b25012b5561.tar.bz2 busybox-w32-48a9971bd41a6ad7fc2ee52dcc885b25012b5561.zip |
unzip: move check for unsupported zip features to better place
-rw-r--r-- | archival/unzip.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index 36490cb41..1c9bc246c 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -99,12 +99,6 @@ static void unzip_create_leading_dirs(const char *fn) | |||
99 | 99 | ||
100 | static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) | 100 | static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) |
101 | { | 101 | { |
102 | if (zip_header->formatted.flags & (0x0008|0x0001)) { | ||
103 | /* 0x0001 - encrypted */ | ||
104 | /* 0x0008 - streaming. [u]cmpsize can be reliably gotten | ||
105 | * only from Central Directory. See unzip_doc.txt */ | ||
106 | bb_error_msg_and_die("zip flags 8 and 1 are not supported"); | ||
107 | } | ||
108 | if (zip_header->formatted.method == 0) { | 102 | if (zip_header->formatted.method == 0) { |
109 | /* Method 0 - stored (not compressed) */ | 103 | /* Method 0 - stored (not compressed) */ |
110 | off_t size = zip_header->formatted.ucmpsize; | 104 | off_t size = zip_header->formatted.ucmpsize; |
@@ -264,10 +258,11 @@ int unzip_main(int argc, char **argv) | |||
264 | 258 | ||
265 | /* Check magic number */ | 259 | /* Check magic number */ |
266 | xread(src_fd, &magic, 4); | 260 | xread(src_fd, &magic, 4); |
261 | /* Central directory? It's at the end, so exit */ | ||
267 | if (magic == ZIP_CDS_MAGIC) | 262 | if (magic == ZIP_CDS_MAGIC) |
268 | break; | 263 | break; |
269 | if (magic != ZIP_FILEHEADER_MAGIC) | 264 | if (magic != ZIP_FILEHEADER_MAGIC) |
270 | bb_error_msg_and_die("invalid zip magic %08X", magic); | 265 | bb_error_msg_and_die("invalid zip magic %08X", (int)magic); |
271 | 266 | ||
272 | /* Read the file header */ | 267 | /* Read the file header */ |
273 | xread(src_fd, zip_header.raw, ZIP_HEADER_LEN); | 268 | xread(src_fd, zip_header.raw, ZIP_HEADER_LEN); |
@@ -275,6 +270,12 @@ int unzip_main(int argc, char **argv) | |||
275 | if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) { | 270 | if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) { |
276 | bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method); | 271 | bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method); |
277 | } | 272 | } |
273 | if (zip_header.formatted.flags & (0x0008|0x0001)) { | ||
274 | /* 0x0001 - encrypted */ | ||
275 | /* 0x0008 - streaming. [u]cmpsize can be reliably gotten | ||
276 | * only from Central Directory. See unzip_doc.txt */ | ||
277 | bb_error_msg_and_die("zip flags 8 and 1 are not supported"); | ||
278 | } | ||
278 | 279 | ||
279 | /* Read filename */ | 280 | /* Read filename */ |
280 | free(dst_fn); | 281 | free(dst_fn); |
@@ -331,7 +332,7 @@ int unzip_main(int argc, char **argv) | |||
331 | i = 'n'; | 332 | i = 'n'; |
332 | 333 | ||
333 | } else { /* Extract file */ | 334 | } else { /* Extract file */ |
334 | _check_file: | 335 | check_file: |
335 | if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */ | 336 | if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */ |
336 | if (errno != ENOENT) { | 337 | if (errno != ENOENT) { |
337 | bb_perror_msg_and_die("cannot stat '%s'", dst_fn); | 338 | bb_perror_msg_and_die("cannot stat '%s'", dst_fn); |
@@ -390,18 +391,19 @@ int unzip_main(int argc, char **argv) | |||
390 | free(dst_fn); | 391 | free(dst_fn); |
391 | dst_fn = xstrdup(key_buf); | 392 | dst_fn = xstrdup(key_buf); |
392 | chomp(dst_fn); | 393 | chomp(dst_fn); |
393 | goto _check_file; | 394 | goto check_file; |
394 | 395 | ||
395 | default: | 396 | default: |
396 | printf("error: invalid response [%c]\n",(char)i); | 397 | printf("error: invalid response [%c]\n",(char)i); |
397 | goto _check_file; | 398 | goto check_file; |
398 | } | 399 | } |
399 | 400 | ||
400 | /* Data descriptor section */ | 401 | // Looks like bug (data descriptor cannot be identified this way) |
401 | if (zip_header.formatted.flags & 4) { | 402 | // /* Data descriptor section */ |
402 | /* skip over duplicate crc, compressed size and uncompressed size */ | 403 | // if (zip_header.formatted.flags & 4) { |
403 | unzip_skip(src_fd, 12); | 404 | // /* skip over duplicate crc, compressed size and uncompressed size */ |
404 | } | 405 | // unzip_skip(src_fd, 12); |
406 | // } | ||
405 | } | 407 | } |
406 | 408 | ||
407 | if (listing && verbose) { | 409 | if (listing && verbose) { |