6728376: Wrong error handling in Java_java_util_zip_Deflater_deflateBytes leads to size 0 if compress fails
6735255: ZipFile.close() does not close ZipFileInputStreams, contrary to the API document Throws OOM when malloc failed. Closes all outstanding streams when closing Reviewed-by: alanb
This commit is contained in:
parent
a1958b22ef
commit
c27639c4d2
@ -32,6 +32,8 @@ import java.io.File;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import static java.util.zip.ZipConstants64.*;
|
import static java.util.zip.ZipConstants64.*;
|
||||||
|
|
||||||
@ -277,6 +279,9 @@ class ZipFile implements ZipConstants {
|
|||||||
// freeEntry releases the C jzentry struct.
|
// freeEntry releases the C jzentry struct.
|
||||||
private static native void freeEntry(long jzfile, long jzentry);
|
private static native void freeEntry(long jzfile, long jzentry);
|
||||||
|
|
||||||
|
// the outstanding inputstreams that need to be closed.
|
||||||
|
private Set<ZipFileInputStream> streams = new HashSet<ZipFileInputStream>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an input stream for reading the contents of the specified
|
* Returns an input stream for reading the contents of the specified
|
||||||
* zip file entry.
|
* zip file entry.
|
||||||
@ -308,6 +313,7 @@ class ZipFile implements ZipConstants {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
in = new ZipFileInputStream(jzentry);
|
in = new ZipFileInputStream(jzentry);
|
||||||
|
streams.add(in);
|
||||||
}
|
}
|
||||||
final ZipFileInputStream zfin = in;
|
final ZipFileInputStream zfin = in;
|
||||||
switch (getEntryMethod(jzentry)) {
|
switch (getEntryMethod(jzentry)) {
|
||||||
@ -323,7 +329,7 @@ class ZipFile implements ZipConstants {
|
|||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
if (!isClosed) {
|
if (!isClosed) {
|
||||||
releaseInflater(inf);
|
releaseInflater(inf);
|
||||||
this.in.close();
|
this.in.close();
|
||||||
isClosed = true;
|
isClosed = true;
|
||||||
}
|
}
|
||||||
@ -497,6 +503,13 @@ class ZipFile implements ZipConstants {
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
closeRequested = true;
|
closeRequested = true;
|
||||||
|
|
||||||
|
if (streams.size() !=0) {
|
||||||
|
Set<ZipFileInputStream> copy = streams;
|
||||||
|
streams = new HashSet<ZipFileInputStream>();
|
||||||
|
for (ZipFileInputStream is: copy)
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
|
||||||
if (jzfile != 0) {
|
if (jzfile != 0) {
|
||||||
// Close the zip file
|
// Close the zip file
|
||||||
long zf = this.jzfile;
|
long zf = this.jzfile;
|
||||||
@ -631,9 +644,9 @@ class ZipFile implements ZipConstants {
|
|||||||
freeEntry(ZipFile.this.jzfile, jzentry);
|
freeEntry(ZipFile.this.jzfile, jzentry);
|
||||||
jzentry = 0;
|
jzentry = 0;
|
||||||
}
|
}
|
||||||
|
streams.remove(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,6 +138,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this,
|
|||||||
|
|
||||||
in_buf = (jbyte *) malloc(this_len);
|
in_buf = (jbyte *) malloc(this_len);
|
||||||
if (in_buf == 0) {
|
if (in_buf == 0) {
|
||||||
|
JNU_ThrowOutOfMemoryError(env, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
||||||
@ -145,6 +146,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this,
|
|||||||
out_buf = (jbyte *) malloc(len);
|
out_buf = (jbyte *) malloc(len);
|
||||||
if (out_buf == 0) {
|
if (out_buf == 0) {
|
||||||
free(in_buf);
|
free(in_buf);
|
||||||
|
JNU_ThrowOutOfMemoryError(env, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +181,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this,
|
|||||||
|
|
||||||
in_buf = (jbyte *) malloc(this_len);
|
in_buf = (jbyte *) malloc(this_len);
|
||||||
if (in_buf == 0) {
|
if (in_buf == 0) {
|
||||||
|
JNU_ThrowOutOfMemoryError(env, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
||||||
@ -186,6 +189,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this,
|
|||||||
out_buf = (jbyte *) malloc(len);
|
out_buf = (jbyte *) malloc(len);
|
||||||
if (out_buf == 0) {
|
if (out_buf == 0) {
|
||||||
free(in_buf);
|
free(in_buf);
|
||||||
|
JNU_ThrowOutOfMemoryError(env, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +125,7 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this,
|
|||||||
|
|
||||||
in_buf = (jbyte *) malloc(this_len);
|
in_buf = (jbyte *) malloc(this_len);
|
||||||
if (in_buf == 0) {
|
if (in_buf == 0) {
|
||||||
|
JNU_ThrowOutOfMemoryError(env, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
||||||
@ -132,6 +133,7 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this,
|
|||||||
out_buf = (jbyte *) malloc(len);
|
out_buf = (jbyte *) malloc(len);
|
||||||
if (out_buf == 0) {
|
if (out_buf == 0) {
|
||||||
free(in_buf);
|
free(in_buf);
|
||||||
|
JNU_ThrowOutOfMemoryError(env, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user