Skip to content

Commit

Permalink
Values in ZIP files are unsigned.
Browse files Browse the repository at this point in the history
Bug: 9695860
Change-Id: I5c12dc5f3c70a9fe081adf5bf5b6b4b3a115e7e1
  • Loading branch information
enh-google authored and rmcc committed Jul 11, 2013
1 parent ac16122 commit 35d2187
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions luni/src/main/java/java/util/zip/ZipEntry.java
Expand Up @@ -366,24 +366,24 @@ public int hashCode() {
}

it.seek(8);
int gpbf = it.readShort();
int gpbf = it.readShort() & 0xffff;

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

compressionMethod = it.readShort();
time = it.readShort();
modDate = it.readShort();
compressionMethod = it.readShort() & 0xffff;
time = it.readShort() & 0xffff;
modDate = it.readShort() & 0xffff;

// These are 32-bit values in the file, but 64-bit fields in this object.
crc = ((long) it.readInt()) & 0xffffffffL;
compressedSize = ((long) it.readInt()) & 0xffffffffL;
size = ((long) it.readInt()) & 0xffffffffL;

nameLength = it.readShort();
int extraLength = it.readShort();
int commentByteCount = it.readShort();
nameLength = it.readShort() & 0xffff;
int extraLength = it.readShort() & 0xffff;
int commentByteCount = it.readShort() & 0xffff;

// This is a 32-bit value in the file, but a 64-bit field in this object.
it.seek(42);
Expand Down
4 changes: 2 additions & 2 deletions luni/src/main/java/java/util/zip/ZipFile.java
Expand Up @@ -264,15 +264,15 @@ public InputStream getInputStream(ZipEntry entry) throws IOException {
// http://www.pkware.com/documents/casestudies/APPNOTE.TXT
RAFStream rafStream= new RAFStream(raf, entry.mLocalHeaderRelOffset + 6);
DataInputStream is = new DataInputStream(rafStream);
int gpbf = Short.reverseBytes(is.readShort());
int gpbf = Short.reverseBytes(is.readShort()) & 0xffff;
if ((gpbf & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
}

// At position 28 we find the length of the extra data. In some cases
// this length differs from the one coming in the central header.
is.skipBytes(20);
int localExtraLenOrWhatever = Short.reverseBytes(is.readShort());
int localExtraLenOrWhatever = Short.reverseBytes(is.readShort()) & 0xffff;
is.close();

// Skip the name and this "extra" data or whatever it is:
Expand Down

0 comments on commit 35d2187

Please sign in to comment.