From c48199457bc0ed96404414ba4d4ad15e4f0fd6bb Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Thu, 7 Aug 2014 18:43:57 +0000 Subject: Revert "Remove nameLength field from ZipEntry." This reverts commit c4da34ca5792e0c73577f868249fdfe8a11a01f6. Change-Id: I1b93ecfcb8a867a670af717eb25c7076b7097d5c --- luni/src/main/java/java/util/zip/ZipEntry.java | 7 +++++-- luni/src/main/native/java_util_jar_StrictJarFile.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/luni/src/main/java/java/util/zip/ZipEntry.java b/luni/src/main/java/java/util/zip/ZipEntry.java index d007b0f..217cc3c 100644 --- a/luni/src/main/java/java/util/zip/ZipEntry.java +++ b/luni/src/main/java/java/util/zip/ZipEntry.java @@ -52,6 +52,7 @@ public class ZipEntry implements ZipConstants, Cloneable { byte[] extra; + int nameLength = -1; long localHeaderRelOffset = -1; long dataOffset = -1; @@ -68,7 +69,7 @@ public class ZipEntry implements ZipConstants, Cloneable { ZipEntry(String name, String comment, long crc, long compressedSize, long size, int compressionMethod, int time, int modDate, byte[] extra, - long localHeaderRelOffset, long dataOffset) { + int nameLength, long localHeaderRelOffset, long dataOffset) { this.name = name; this.comment = comment; this.crc = crc; @@ -78,6 +79,7 @@ public class ZipEntry implements ZipConstants, Cloneable { this.time = time; this.modDate = modDate; this.extra = extra; + this.nameLength = nameLength; this.localHeaderRelOffset = localHeaderRelOffset; this.dataOffset = dataOffset; } @@ -338,6 +340,7 @@ public class ZipEntry implements ZipConstants, Cloneable { compressionMethod = ze.compressionMethod; modDate = ze.modDate; extra = ze.extra; + nameLength = ze.nameLength; localHeaderRelOffset = ze.localHeaderRelOffset; dataOffset = ze.dataOffset; } @@ -409,7 +412,7 @@ public class ZipEntry implements ZipConstants, Cloneable { compressedSize = ((long) it.readInt()) & 0xffffffffL; size = ((long) it.readInt()) & 0xffffffffL; - int nameLength = it.readShort() & 0xffff; + nameLength = it.readShort() & 0xffff; int extraLength = it.readShort() & 0xffff; int commentByteCount = it.readShort() & 0xffff; diff --git a/luni/src/main/native/java_util_jar_StrictJarFile.cpp b/luni/src/main/native/java_util_jar_StrictJarFile.cpp index 715082b..7611749 100644 --- a/luni/src/main/native/java_util_jar_StrictJarFile.cpp +++ b/luni/src/main/native/java_util_jar_StrictJarFile.cpp @@ -32,7 +32,8 @@ static void throwIoException(JNIEnv* env, const int32_t errorCode) { jniThrowException(env, "java/io/IOException", ErrorCodeString(errorCode)); } -static jobject newZipEntry(JNIEnv* env, const ZipEntry& entry, jstring entryName) { +static jobject newZipEntry(JNIEnv* env, const ZipEntry& entry, jstring entryName, + const uint16_t nameLength) { ScopedLocalRef zipEntryClass(env, env->FindClass("java/util/zip/ZipEntry")); const jmethodID zipEntryCtor = env->GetMethodID(zipEntryClass.get(), "", "(Ljava/lang/String;Ljava/lang/String;JJJIII[BIJJ)V"); @@ -48,6 +49,7 @@ static jobject newZipEntry(JNIEnv* env, const ZipEntry& entry, jstring entryName static_cast(0), // time static_cast(0), // modData NULL, // byte[] extra + static_cast(nameLength), static_cast(-1), // local header offset static_cast(entry.offset)); } @@ -133,7 +135,7 @@ static jobject StrictJarFile_nativeNextEntry(JNIEnv* env, jobject, jlong iterati entryNameCString[entryName.name_length] = '\0'; ScopedLocalRef entryNameString(env, env->NewStringUTF(entryNameCString.get())); - return newZipEntry(env, data, entryNameString.get()); + return newZipEntry(env, data, entryNameString.get(), entryName.name_length); } static jobject StrictJarFile_nativeFindEntry(JNIEnv* env, jobject, jlong nativeHandle, @@ -150,7 +152,7 @@ static jobject StrictJarFile_nativeFindEntry(JNIEnv* env, jobject, jlong nativeH return NULL; } - return newZipEntry(env, data, entryName); + return newZipEntry(env, data, entryName, entryNameChars.size()); } static void StrictJarFile_nativeClose(JNIEnv*, jobject, jlong nativeHandle) { -- cgit v1.1