unzip: move check for unsupported zip features to better place

This commit is contained in:
Denis Vlasenko 2008-07-26 17:32:41 +00:00
parent c2dcb7cf63
commit 48a9971bd4

View File

@ -99,12 +99,6 @@ static void unzip_create_leading_dirs(const char *fn)
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 @@ int unzip_main(int argc, char **argv)
/* 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 @@ int unzip_main(int argc, char **argv)
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 @@ int unzip_main(int argc, char **argv)
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 @@ int unzip_main(int argc, char **argv)
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) {