簡體   English   中英

java.util.zip.ZipException:無效的通用標志:9

[英]java.util.zip.ZipException: invalid general purpose flag: 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/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設置了“加密文件”和“數據描述符”位。

在這里可以窺見Android源代碼: https//chromium.googlesource.com/android_tools/+/9e9b6169a098bc19986e44fbbf65e4c29031e4bd/sdk/sources/android-22/java/util/zip/ZipFile.java (舊版本,但我懷疑是這沒有改變)顯示此:

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實現不支持讀取加密的文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM