提交 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,6 +132,8 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr, ...@@ -132,6 +132,8 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
in_buf = (jbyte *) malloc(this_len); in_buf = (jbyte *) malloc(this_len);
if (in_buf == 0) { if (in_buf == 0) {
// Throw OOME only when length is not zero
if (this_len != 0)
JNU_ThrowOutOfMemoryError(env, 0); JNU_ThrowOutOfMemoryError(env, 0);
return 0; return 0;
} }
...@@ -139,6 +141,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr, ...@@ -139,6 +141,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
out_buf = (jbyte *) malloc(len); out_buf = (jbyte *) malloc(len);
if (out_buf == 0) { if (out_buf == 0) {
free(in_buf); free(in_buf);
if (len != 0)
JNU_ThrowOutOfMemoryError(env, 0); JNU_ThrowOutOfMemoryError(env, 0);
return 0; return 0;
} }
...@@ -173,6 +176,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr, ...@@ -173,6 +176,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
jboolean finish = (*env)->GetBooleanField(env, this, finishID); jboolean finish = (*env)->GetBooleanField(env, this, finishID);
in_buf = (jbyte *) malloc(this_len); in_buf = (jbyte *) malloc(this_len);
if (in_buf == 0) { if (in_buf == 0) {
if (this_len != 0)
JNU_ThrowOutOfMemoryError(env, 0); JNU_ThrowOutOfMemoryError(env, 0);
return 0; return 0;
} }
...@@ -181,6 +185,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr, ...@@ -181,6 +185,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
out_buf = (jbyte *) malloc(len); out_buf = (jbyte *) malloc(len);
if (out_buf == 0) { if (out_buf == 0) {
free(in_buf); free(in_buf);
if (len != 0)
JNU_ThrowOutOfMemoryError(env, 0); JNU_ThrowOutOfMemoryError(env, 0);
return 0; return 0;
} }
......
...@@ -135,6 +135,7 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr, ...@@ -135,6 +135,7 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr,
in_buf = (jbyte *) malloc(in_len); in_buf = (jbyte *) malloc(in_len);
if (in_buf == 0) { if (in_buf == 0) {
if (in_len != 0)
JNU_ThrowOutOfMemoryError(env, 0); JNU_ThrowOutOfMemoryError(env, 0);
return 0; return 0;
} }
...@@ -143,6 +144,7 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr, ...@@ -143,6 +144,7 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr,
out_buf = (jbyte *) malloc(len); out_buf = (jbyte *) malloc(len);
if (out_buf == 0) { if (out_buf == 0) {
free(in_buf); free(in_buf);
if (len != 0)
JNU_ThrowOutOfMemoryError(env, 0); JNU_ThrowOutOfMemoryError(env, 0);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册