提交 4614b93b 编写于 作者: S sherman

6858865: Fix for 6728376 causes regression if the size of "data" is 0 and...

6858865: Fix for 6728376 causes regression if the size of "data" is 0 and malloc returns Null for 0-length
Summary: don't throw OOME when in or out buffer size is 0 length
Reviewed-by: alanb
上级 bcc6059a
......@@ -132,14 +132,17 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
in_buf = (jbyte *) malloc(this_len);
if (in_buf == 0) {
JNU_ThrowOutOfMemoryError(env, 0);
// Throw OOME only when length is not zero
if (this_len != 0)
JNU_ThrowOutOfMemoryError(env, 0);
return 0;
}
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
out_buf = (jbyte *) malloc(len);
if (out_buf == 0) {
free(in_buf);
JNU_ThrowOutOfMemoryError(env, 0);
if (len != 0)
JNU_ThrowOutOfMemoryError(env, 0);
return 0;
}
......@@ -173,7 +176,8 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
jboolean finish = (*env)->GetBooleanField(env, this, finishID);
in_buf = (jbyte *) malloc(this_len);
if (in_buf == 0) {
JNU_ThrowOutOfMemoryError(env, 0);
if (this_len != 0)
JNU_ThrowOutOfMemoryError(env, 0);
return 0;
}
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
......@@ -181,7 +185,8 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
out_buf = (jbyte *) malloc(len);
if (out_buf == 0) {
free(in_buf);
JNU_ThrowOutOfMemoryError(env, 0);
if (len != 0)
JNU_ThrowOutOfMemoryError(env, 0);
return 0;
}
......
......@@ -135,7 +135,8 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr,
in_buf = (jbyte *) malloc(in_len);
if (in_buf == 0) {
JNU_ThrowOutOfMemoryError(env, 0);
if (in_len != 0)
JNU_ThrowOutOfMemoryError(env, 0);
return 0;
}
(*env)->GetByteArrayRegion(env, this_buf, this_off, in_len, in_buf);
......@@ -143,7 +144,8 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr,
out_buf = (jbyte *) malloc(len);
if (out_buf == 0) {
free(in_buf);
JNU_ThrowOutOfMemoryError(env, 0);
if (len != 0)
JNU_ThrowOutOfMemoryError(env, 0);
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册