Skip to content

Commit

Permalink
Only enforce the encrypted bit in the GPBF, and ignore other unsuppor…
Browse files Browse the repository at this point in the history
…ted bits.

(cherry-pick of 7a302a4.)

Bug: 8617715
Change-Id: Ibfe919d67fd17cee050d23811faa5aa64116dfb4
  • Loading branch information
William Luh authored and rmcc committed Jul 11, 2013
1 parent 63cd294 commit ac16122
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion luni/src/main/java/java/util/zip/ZipEntry.java
Expand Up @@ -368,7 +368,7 @@ public int hashCode() {
it.seek(8);
int gpbf = it.readShort();

if ((gpbf & ~ZipFile.GPBF_SUPPORTED_MASK) != 0) {
if ((gpbf & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
}

Expand Down
16 changes: 13 additions & 3 deletions luni/src/main/java/java/util/zip/ZipFile.java
Expand Up @@ -47,6 +47,12 @@
* an existing zip file.
*/
public class ZipFile implements ZipConstants {
/**
* General Purpose Bit Flags, Bit 0.
* If set, indicates that the file is encrypted.
*/
static final int GPBF_ENCRYPTED_FLAG = 1 << 0;

/**
* General Purpose Bit Flags, Bit 3.
* If this bit is set, the fields crc-32, compressed
Expand All @@ -70,9 +76,13 @@ public class ZipFile implements ZipConstants {

/**
* Supported General Purpose Bit Flags Mask.
* Bit mask of supported GPBF bits.
* 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_SUPPORTED_MASK = GPBF_DATA_DESCRIPTOR_FLAG | GPBF_UTF8_FLAG;
static final int GPBF_UNSUPPORTED_MASK = GPBF_ENCRYPTED_FLAG;

/**
* Open zip file for reading.
Expand Down Expand Up @@ -255,7 +265,7 @@ public InputStream getInputStream(ZipEntry entry) throws IOException {
RAFStream rafStream= new RAFStream(raf, entry.mLocalHeaderRelOffset + 6);
DataInputStream is = new DataInputStream(rafStream);
int gpbf = Short.reverseBytes(is.readShort());
if ((gpbf & ~ZipFile.GPBF_SUPPORTED_MASK) != 0) {
if ((gpbf & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
}

Expand Down
2 changes: 1 addition & 1 deletion luni/src/main/java/java/util/zip/ZipInputStream.java
Expand Up @@ -240,7 +240,7 @@ public ZipEntry getNextEntry() throws IOException {
throw new ZipException("Cannot read local header version " + version);
}
int flags = peekShort(LOCFLG - LOCVER);
if ((flags & ~ZipFile.GPBF_SUPPORTED_MASK) != 0) {
if ((flags & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + flags);
}

Expand Down

0 comments on commit ac16122

Please sign in to comment.