diff options
Diffstat (limited to 'luni/src/main/java/java/util/zip/ZipFile.java')
-rw-r--r-- | luni/src/main/java/java/util/zip/ZipFile.java | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/luni/src/main/java/java/util/zip/ZipFile.java b/luni/src/main/java/java/util/zip/ZipFile.java index 7decdc5..2f2284a 100644 --- a/luni/src/main/java/java/util/zip/ZipFile.java +++ b/luni/src/main/java/java/util/zip/ZipFile.java @@ -269,19 +269,23 @@ public class ZipFile implements ZipConstants { 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()) & 0xffff; + // Offset 26 has the file name length, and offset 28 has the extra field length. + // These lengths can differ from the ones in the central header. + is.skipBytes(18); + int fileNameLength = Short.reverseBytes(is.readShort()) & 0xffff; + int extraFieldLength = Short.reverseBytes(is.readShort()) & 0xffff; is.close(); - // Skip the name and this "extra" data or whatever it is: - rafStream.skip(entry.nameLength + localExtraLenOrWhatever); - rafStream.mLength = rafStream.mOffset + entry.compressedSize; + // Skip the variable-size file name and extra field data. + rafStream.skip(fileNameLength + extraFieldLength); + + // The compressed or stored file data follows immediately after. if (entry.compressionMethod == ZipEntry.DEFLATED) { - int bufSize = Math.max(1024, (int)Math.min(entry.getSize(), 65535L)); + rafStream.mLength = rafStream.mOffset + entry.compressedSize; + int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L)); return new ZipInflaterInputStream(rafStream, new Inflater(true), bufSize, entry); } else { + rafStream.mLength = rafStream.mOffset + entry.size; return rafStream; } } |