author | fparain |
Thu, 09 Oct 2014 04:48:12 -0700 | |
changeset 27184 | 2996674bd701 |
parent 25859 | 3317bb8137f4 |
child 27186 | c1b8debdfcc2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22643
ba2891b3f866
8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents:
18223
diff
changeset
|
2 |
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
/* |
|
27 |
* Native method support for java.util.zip.ZipFile |
|
28 |
*/ |
|
29 |
||
30 |
#include <stdio.h> |
|
31 |
#include <stdlib.h> |
|
32 |
#include <string.h> |
|
33 |
#include <errno.h> |
|
34 |
#include <ctype.h> |
|
35 |
#include <assert.h> |
|
36 |
#include "jlong.h" |
|
37 |
#include "jvm.h" |
|
38 |
#include "jni.h" |
|
39 |
#include "jni_util.h" |
|
40 |
#include "zip_util.h" |
|
41 |
#ifdef WIN32 |
|
42 |
#include "io_util_md.h" |
|
3078 | 43 |
#else |
44 |
#include "io_util.h" |
|
2 | 45 |
#endif |
46 |
||
47 |
#include "java_util_zip_ZipFile.h" |
|
48 |
#include "java_util_jar_JarFile.h" |
|
49 |
||
50 |
#define DEFLATED 8 |
|
51 |
#define STORED 0 |
|
52 |
||
53 |
static jfieldID jzfileID; |
|
54 |
||
55 |
static int OPEN_READ = java_util_zip_ZipFile_OPEN_READ; |
|
56 |
static int OPEN_DELETE = java_util_zip_ZipFile_OPEN_DELETE; |
|
57 |
||
58 |
JNIEXPORT void JNICALL |
|
59 |
Java_java_util_zip_ZipFile_initIDs(JNIEnv *env, jclass cls) |
|
60 |
{ |
|
61 |
jzfileID = (*env)->GetFieldID(env, cls, "jzfile", "J"); |
|
62 |
assert(jzfileID != 0); |
|
63 |
} |
|
64 |
||
65 |
static void |
|
66 |
ThrowZipException(JNIEnv *env, const char *msg) |
|
67 |
{ |
|
68 |
jstring s = NULL; |
|
69 |
jobject x; |
|
70 |
||
71 |
if (msg != NULL) { |
|
72 |
s = JNU_NewStringPlatform(env, msg); |
|
73 |
} |
|
22643
ba2891b3f866
8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents:
18223
diff
changeset
|
74 |
if (s != NULL) { |
ba2891b3f866
8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents:
18223
diff
changeset
|
75 |
x = JNU_NewObjectByName(env, |
2 | 76 |
"java/util/zip/ZipException", |
77 |
"(Ljava/lang/String;)V", s); |
|
22643
ba2891b3f866
8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents:
18223
diff
changeset
|
78 |
if (x != NULL) { |
ba2891b3f866
8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents:
18223
diff
changeset
|
79 |
(*env)->Throw(env, x); |
ba2891b3f866
8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents:
18223
diff
changeset
|
80 |
} |
2 | 81 |
} |
82 |
} |
|
83 |
||
84 |
JNIEXPORT jlong JNICALL |
|
85 |
Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name, |
|
5148
2bf5469864ea
6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents:
3078
diff
changeset
|
86 |
jint mode, jlong lastModified, |
2bf5469864ea
6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents:
3078
diff
changeset
|
87 |
jboolean usemmap) |
2 | 88 |
{ |
89 |
const char *path = JNU_GetStringPlatformChars(env, name, 0); |
|
90 |
char *msg = 0; |
|
91 |
jlong result = 0; |
|
92 |
int flag = 0; |
|
93 |
jzfile *zip = 0; |
|
94 |
||
95 |
if (mode & OPEN_READ) flag |= O_RDONLY; |
|
96 |
||
97 |
if (path != 0) { |
|
98 |
zip = ZIP_Get_From_Cache(path, &msg, lastModified); |
|
99 |
if (zip == 0 && msg == 0) { |
|
100 |
ZFILE zfd = 0; |
|
101 |
#ifdef WIN32 |
|
27184 | 102 |
if (mode & OPEN_DELETE) flag |= O_TEMPORARY; |
2 | 103 |
zfd = winFileHandleOpen(env, name, flag); |
104 |
if (zfd == -1) { |
|
105 |
/* Exception already pending. */ |
|
106 |
goto finally; |
|
107 |
} |
|
108 |
#else |
|
27184 | 109 |
zfd = open(path, flag, 0); |
3078 | 110 |
if (zfd < 0) { |
111 |
throwFileNotFoundException(env, name); |
|
112 |
goto finally; |
|
113 |
} |
|
27184 | 114 |
if (mode & OPEN_DELETE) { |
115 |
unlink(path); |
|
116 |
} |
|
2 | 117 |
#endif |
5148
2bf5469864ea
6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents:
3078
diff
changeset
|
118 |
zip = ZIP_Put_In_Cache0(path, zfd, &msg, lastModified, usemmap); |
2 | 119 |
} |
120 |
||
121 |
if (zip != 0) { |
|
122 |
result = ptr_to_jlong(zip); |
|
123 |
} else if (msg != 0) { |
|
124 |
ThrowZipException(env, msg); |
|
12543
b77bc2f404ba
7159982: ZipFile uses static for error message when malformed zip file encountered
zhouyx
parents:
7668
diff
changeset
|
125 |
free(msg); |
2 | 126 |
} else if (errno == ENOMEM) { |
127 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
128 |
} else { |
|
129 |
ThrowZipException(env, "error in opening zip file"); |
|
130 |
} |
|
131 |
finally: |
|
132 |
JNU_ReleaseStringPlatformChars(env, name, path); |
|
133 |
} |
|
134 |
return result; |
|
135 |
} |
|
136 |
||
137 |
JNIEXPORT jint JNICALL |
|
138 |
Java_java_util_zip_ZipFile_getTotal(JNIEnv *env, jclass cls, jlong zfile) |
|
139 |
{ |
|
140 |
jzfile *zip = jlong_to_ptr(zfile); |
|
141 |
||
142 |
return zip->total; |
|
143 |
} |
|
144 |
||
18223
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
14342
diff
changeset
|
145 |
JNIEXPORT jboolean JNICALL |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
14342
diff
changeset
|
146 |
Java_java_util_zip_ZipFile_startsWithLOC(JNIEnv *env, jclass cls, jlong zfile) |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
14342
diff
changeset
|
147 |
{ |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
14342
diff
changeset
|
148 |
jzfile *zip = jlong_to_ptr(zfile); |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
14342
diff
changeset
|
149 |
|
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
14342
diff
changeset
|
150 |
return zip->locsig; |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
14342
diff
changeset
|
151 |
} |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
14342
diff
changeset
|
152 |
|
2 | 153 |
JNIEXPORT void JNICALL |
154 |
Java_java_util_zip_ZipFile_close(JNIEnv *env, jclass cls, jlong zfile) |
|
155 |
{ |
|
156 |
ZIP_Close(jlong_to_ptr(zfile)); |
|
157 |
} |
|
158 |
||
159 |
JNIEXPORT jlong JNICALL |
|
160 |
Java_java_util_zip_ZipFile_getEntry(JNIEnv *env, jclass cls, jlong zfile, |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
161 |
jbyteArray name, jboolean addSlash) |
2 | 162 |
{ |
163 |
#define MAXNAME 1024 |
|
164 |
jzfile *zip = jlong_to_ptr(zfile); |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
165 |
jsize ulen = (*env)->GetArrayLength(env, name); |
2 | 166 |
char buf[MAXNAME+2], *path; |
167 |
jzentry *ze; |
|
168 |
||
169 |
if (ulen > MAXNAME) { |
|
170 |
path = malloc(ulen + 2); |
|
171 |
if (path == 0) { |
|
172 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
173 |
return 0; |
|
174 |
} |
|
175 |
} else { |
|
176 |
path = buf; |
|
177 |
} |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
178 |
(*env)->GetByteArrayRegion(env, name, 0, ulen, (jbyte *)path); |
2 | 179 |
path[ulen] = '\0'; |
180 |
if (addSlash == JNI_FALSE) { |
|
181 |
ze = ZIP_GetEntry(zip, path, 0); |
|
182 |
} else { |
|
183 |
ze = ZIP_GetEntry(zip, path, (jint)ulen); |
|
184 |
} |
|
185 |
if (path != buf) { |
|
186 |
free(path); |
|
187 |
} |
|
188 |
return ptr_to_jlong(ze); |
|
189 |
} |
|
190 |
||
191 |
JNIEXPORT void JNICALL |
|
192 |
Java_java_util_zip_ZipFile_freeEntry(JNIEnv *env, jclass cls, jlong zfile, |
|
193 |
jlong zentry) |
|
194 |
{ |
|
195 |
jzfile *zip = jlong_to_ptr(zfile); |
|
196 |
jzentry *ze = jlong_to_ptr(zentry); |
|
197 |
ZIP_FreeEntry(zip, ze); |
|
198 |
} |
|
199 |
||
200 |
JNIEXPORT jlong JNICALL |
|
201 |
Java_java_util_zip_ZipFile_getNextEntry(JNIEnv *env, jclass cls, jlong zfile, |
|
202 |
jint n) |
|
203 |
{ |
|
204 |
jzentry *ze = ZIP_GetNextEntry(jlong_to_ptr(zfile), n); |
|
205 |
return ptr_to_jlong(ze); |
|
206 |
} |
|
207 |
||
208 |
JNIEXPORT jint JNICALL |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
209 |
Java_java_util_zip_ZipFile_getEntryMethod(JNIEnv *env, jclass cls, jlong zentry) |
2 | 210 |
{ |
211 |
jzentry *ze = jlong_to_ptr(zentry); |
|
212 |
return ze->csize != 0 ? DEFLATED : STORED; |
|
213 |
} |
|
214 |
||
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
215 |
JNIEXPORT jint JNICALL |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
216 |
Java_java_util_zip_ZipFile_getEntryFlag(JNIEnv *env, jclass cls, jlong zentry) |
2 | 217 |
{ |
218 |
jzentry *ze = jlong_to_ptr(zentry); |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
219 |
return ze->flag; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
220 |
} |
2 | 221 |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
222 |
JNIEXPORT jlong JNICALL |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
223 |
Java_java_util_zip_ZipFile_getEntryCSize(JNIEnv *env, jclass cls, jlong zentry) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
224 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
225 |
jzentry *ze = jlong_to_ptr(zentry); |
2 | 226 |
return ze->csize != 0 ? ze->csize : ze->size; |
227 |
} |
|
228 |
||
229 |
JNIEXPORT jlong JNICALL |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
230 |
Java_java_util_zip_ZipFile_getEntrySize(JNIEnv *env, jclass cls, jlong zentry) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
231 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
232 |
jzentry *ze = jlong_to_ptr(zentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
233 |
return ze->size; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
234 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
235 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
236 |
JNIEXPORT jlong JNICALL |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
237 |
Java_java_util_zip_ZipFile_getEntryTime(JNIEnv *env, jclass cls, jlong zentry) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
238 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
239 |
jzentry *ze = jlong_to_ptr(zentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
240 |
return (jlong)ze->time & 0xffffffffUL; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
241 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
242 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
243 |
JNIEXPORT jlong JNICALL |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
244 |
Java_java_util_zip_ZipFile_getEntryCrc(JNIEnv *env, jclass cls, jlong zentry) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
245 |
{ |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
246 |
jzentry *ze = jlong_to_ptr(zentry); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
247 |
return (jlong)ze->crc & 0xffffffffUL; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
248 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
249 |
|
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
250 |
JNIEXPORT jbyteArray JNICALL |
3078 | 251 |
Java_java_util_zip_ZipFile_getCommentBytes(JNIEnv *env, |
252 |
jclass cls, |
|
253 |
jlong zfile) |
|
254 |
{ |
|
255 |
jzfile *zip = jlong_to_ptr(zfile); |
|
256 |
jbyteArray jba = NULL; |
|
257 |
||
258 |
if (zip->comment != NULL) { |
|
259 |
if ((jba = (*env)->NewByteArray(env, zip->clen)) == NULL) |
|
260 |
return NULL; |
|
261 |
(*env)->SetByteArrayRegion(env, jba, 0, zip->clen, (jbyte*)zip->comment); |
|
262 |
} |
|
263 |
return jba; |
|
264 |
} |
|
265 |
||
266 |
JNIEXPORT jbyteArray JNICALL |
|
267 |
Java_java_util_zip_ZipFile_getEntryBytes(JNIEnv *env, |
|
268 |
jclass cls, |
|
269 |
jlong zentry, jint type) |
|
2 | 270 |
{ |
271 |
jzentry *ze = jlong_to_ptr(zentry); |
|
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
272 |
int len = 0; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
273 |
jbyteArray jba = NULL; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
274 |
switch (type) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
275 |
case java_util_zip_ZipFile_JZENTRY_NAME: |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
276 |
if (ze->name != 0) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
277 |
len = (int)strlen(ze->name); |
25222
5d63cd3696d6
8048990: ZipFile.entries() can't handle empty zip entry names
martin
parents:
22643
diff
changeset
|
278 |
// Unlike for extra and comment, we never return null for |
5d63cd3696d6
8048990: ZipFile.entries() can't handle empty zip entry names
martin
parents:
22643
diff
changeset
|
279 |
// an (extremely rarely seen) empty name |
5d63cd3696d6
8048990: ZipFile.entries() can't handle empty zip entry names
martin
parents:
22643
diff
changeset
|
280 |
if ((jba = (*env)->NewByteArray(env, len)) == NULL) |
2592
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
281 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
282 |
(*env)->SetByteArrayRegion(env, jba, 0, len, (jbyte *)ze->name); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
283 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
284 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
285 |
case java_util_zip_ZipFile_JZENTRY_EXTRA: |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
286 |
if (ze->extra != 0) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
287 |
unsigned char *bp = (unsigned char *)&ze->extra[0]; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
288 |
len = (bp[0] | (bp[1] << 8)); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
289 |
if (len <= 0 || (jba = (*env)->NewByteArray(env, len)) == NULL) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
290 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
291 |
(*env)->SetByteArrayRegion(env, jba, 0, len, &ze->extra[2]); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
292 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
293 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
294 |
case java_util_zip_ZipFile_JZENTRY_COMMENT: |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
295 |
if (ze->comment != 0) { |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
296 |
len = (int)strlen(ze->comment); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
297 |
if (len == 0 || (jba = (*env)->NewByteArray(env, len)) == NULL) |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
298 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
299 |
(*env)->SetByteArrayRegion(env, jba, 0, len, (jbyte*)ze->comment); |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
300 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
301 |
break; |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
302 |
} |
ef26f663a2ba
4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents:
2
diff
changeset
|
303 |
return jba; |
2 | 304 |
} |
305 |
||
306 |
JNIEXPORT jint JNICALL |
|
307 |
Java_java_util_zip_ZipFile_read(JNIEnv *env, jclass cls, jlong zfile, |
|
308 |
jlong zentry, jlong pos, jbyteArray bytes, |
|
309 |
jint off, jint len) |
|
310 |
{ |
|
311 |
jzfile *zip = jlong_to_ptr(zfile); |
|
312 |
char *msg; |
|
313 |
||
314 |
#define BUFSIZE 8192 |
|
315 |
/* copy via tmp stack buffer: */ |
|
316 |
jbyte buf[BUFSIZE]; |
|
317 |
||
318 |
if (len > BUFSIZE) { |
|
319 |
len = BUFSIZE; |
|
320 |
} |
|
321 |
||
322 |
ZIP_Lock(zip); |
|
323 |
len = ZIP_Read(zip, jlong_to_ptr(zentry), pos, buf, len); |
|
324 |
msg = zip->msg; |
|
325 |
ZIP_Unlock(zip); |
|
326 |
if (len != -1) { |
|
327 |
(*env)->SetByteArrayRegion(env, bytes, off, len, buf); |
|
328 |
} |
|
329 |
||
330 |
if (len == -1) { |
|
331 |
if (msg != 0) { |
|
332 |
ThrowZipException(env, msg); |
|
333 |
} else { |
|
334 |
char errmsg[128]; |
|
335 |
sprintf(errmsg, "errno: %d, error: %s\n", |
|
336 |
errno, "Error reading ZIP file"); |
|
337 |
JNU_ThrowIOExceptionWithLastError(env, errmsg); |
|
338 |
} |
|
339 |
} |
|
340 |
||
341 |
return len; |
|
342 |
} |
|
343 |
||
344 |
/* |
|
345 |
* Returns an array of strings representing the names of all entries |
|
346 |
* that begin with "META-INF/" (case ignored). This native method is |
|
347 |
* used in JarFile as an optimization when looking up manifest and |
|
348 |
* signature file entries. Returns null if no entries were found. |
|
349 |
*/ |
|
350 |
JNIEXPORT jobjectArray JNICALL |
|
351 |
Java_java_util_jar_JarFile_getMetaInfEntryNames(JNIEnv *env, jobject obj) |
|
352 |
{ |
|
353 |
jlong zfile = (*env)->GetLongField(env, obj, jzfileID); |
|
354 |
jzfile *zip; |
|
355 |
int i, count; |
|
356 |
jobjectArray result = 0; |
|
357 |
||
358 |
if (zfile == 0) { |
|
359 |
JNU_ThrowByName(env, |
|
360 |
"java/lang/IllegalStateException", "zip file closed"); |
|
361 |
return NULL; |
|
362 |
} |
|
363 |
zip = jlong_to_ptr(zfile); |
|
364 |
||
365 |
/* count the number of valid ZIP metanames */ |
|
366 |
count = 0; |
|
367 |
if (zip->metanames != 0) { |
|
368 |
for (i = 0; i < zip->metacount; i++) { |
|
369 |
if (zip->metanames[i] != 0) { |
|
370 |
count++; |
|
371 |
} |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
/* If some names were found then build array of java strings */ |
|
376 |
if (count > 0) { |
|
22643
ba2891b3f866
8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents:
18223
diff
changeset
|
377 |
jclass cls = JNU_ClassString(env); |
ba2891b3f866
8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents:
18223
diff
changeset
|
378 |
CHECK_NULL_RETURN(cls, NULL); |
2 | 379 |
result = (*env)->NewObjectArray(env, count, cls, 0); |
22643
ba2891b3f866
8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents:
18223
diff
changeset
|
380 |
CHECK_NULL_RETURN(result, NULL); |
2 | 381 |
if (result != 0) { |
382 |
for (i = 0; i < count; i++) { |
|
383 |
jstring str = (*env)->NewStringUTF(env, zip->metanames[i]); |
|
384 |
if (str == 0) { |
|
385 |
break; |
|
386 |
} |
|
387 |
(*env)->SetObjectArrayElement(env, result, i, str); |
|
388 |
(*env)->DeleteLocalRef(env, str); |
|
389 |
} |
|
390 |
} |
|
391 |
} |
|
392 |
return result; |
|
393 |
} |
|
394 |
||
395 |
JNIEXPORT jstring JNICALL |
|
396 |
Java_java_util_zip_ZipFile_getZipMessage(JNIEnv *env, jclass cls, jlong zfile) |
|
397 |
{ |
|
398 |
jzfile *zip = jlong_to_ptr(zfile); |
|
399 |
char *msg = zip->msg; |
|
400 |
if (msg == NULL) { |
|
401 |
return NULL; |
|
402 |
} |
|
403 |
return JNU_NewStringPlatform(env, msg); |
|
404 |
} |