# HG changeset patch # User sherman # Date 1290470593 28800 # Node ID 5616c35fa8113185e5d69154d108595a5165902c # Parent e70d5e55fd1de98f1f814e9f6881f203778edf2e 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 diff -r e70d5e55fd1d -r 5616c35fa811 jdk/src/share/native/java/util/zip/Deflater.c --- a/jdk/src/share/native/java/util/zip/Deflater.c Mon Nov 22 11:27:14 2010 -0500 +++ b/jdk/src/share/native/java/util/zip/Deflater.c Mon Nov 22 16:03:13 2010 -0800 @@ -132,14 +132,17 @@ 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 @@ 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 @@ 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; } diff -r e70d5e55fd1d -r 5616c35fa811 jdk/src/share/native/java/util/zip/Inflater.c --- a/jdk/src/share/native/java/util/zip/Inflater.c Mon Nov 22 11:27:14 2010 -0500 +++ b/jdk/src/share/native/java/util/zip/Inflater.c Mon Nov 22 16:03:13 2010 -0800 @@ -135,7 +135,8 @@ 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 @@ 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; }