简体   繁体   中英

java.util.zip.ZipException: invalid general purpose flag: 9

I get this error on Android 6.0

java.util.zip.ZipException: Invalid General Purpose Bit Flag: 9 java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:253)

And this is my code:

ZipInputStream zin = new ZipInputStream(getAppContext().getContentResolver().openInputStream(uri));

What does it mean? What am I doing wrong?

Here's the ZIP file specification: https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html

Flags   General purpose bit flag:
Bit 00: encrypted file
Bit 01: compression option
Bit 02: compression option
Bit 03: data descriptor
Bit 04: enhanced deflation
Bit 05: compressed patched data
Bit 06: strong encryption
Bit 07-10: unused
Bit 11: language encoding
Bit 12: reserved
Bit 13: mask header values
Bit 14-15: reserved 

So, a GPBF value of 9 has both the "encrypted file" and "data descriptor" bits set.

A peek at the Android source code here: https://chromium.googlesource.com/android_tools/+/9e9b6169a098bc19986e44fbbf65e4c29031e4bd/sdk/sources/android-22/java/util/zip/ZipFile.java (an older version, but I suspect this hasn't changed) shows this:

static final int GPBF_ENCRYPTED_FLAG = 1 << 0;

[...]

/**
 * Supported General Purpose Bit Flags Mask.
 * Bit mask of bits not supported.
 * Note: The only bit that we will enforce at this time
 * is the encrypted bit. Although other bits are not supported,
 * we must not enforce them as this could break some legitimate
 * use cases (See http://b/8617715).
 */
static final int GPBF_UNSUPPORTED_MASK = GPBF_ENCRYPTED_FLAG;

[...]

// At position 6 we find the General Purpose Bit Flag.
int gpbf = Short.reverseBytes(is.readShort()) & 0xffff;
if ((gpbf & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
    throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
}

So, your ZIP file claims to have encrypted the file (bit 00 of the GPBF is set), and the ZipFile implementation doesn't support reading encrypted files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM