6858865: Fix for 6728376 causes regression if the size of "data" is 0 and malloc returns Null for 0-length
authorsherman
Mon, 22 Nov 2010 16:03:13 -0800
changeset 7294 5616c35fa811
parent 7293 e70d5e55fd1d
child 7295 d638f099196f
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
jdk/src/share/native/java/util/zip/Deflater.c
jdk/src/share/native/java/util/zip/Inflater.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;
         }
 
--- 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;
     }