java.util.zip.zipexception:无效通用标志:9



我在Android 6.0

上获取此错误

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

这是我的代码:

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

这是什么意思?我在做什么错?

这是zip文件规范:https://users.cs.jmu.edu/buchhofp/forensics/forensics/formats/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 

因此,GPBF值为9具有"加密文件"one_answers"数据描述符"位。

在此处查看Android源代码:https://chromium.googlesource.com/android_tools//9e9b6169a098bc19986e44444fbbf65e4c29031e4bd/sdk/sdk/sources/sources/android-22/android-22/java/java/java/java/java/jip/zipfile.java.java.jjava.jjava.jjjava(一个较旧的版本,但我怀疑这没有改变)显示了这一点:

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);
}

因此,您的zip文件声称已对文件进行了加密(设置了GPBF的位00),并且zipfile实现不支持读取加密文件。

最新更新