8029854: Enhance JPEG decodings
authorprr
Fri, 20 Dec 2013 09:58:29 -0800
changeset 23892 9959956918be
parent 23891 5b4c7da22eab
child 23893 1a92335b55bb
8029854: Enhance JPEG decodings Reviewed-by: bae, vadim, mschoene
jdk/src/share/native/sun/awt/image/gif/gifdecoder.c
jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c
jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c
--- a/jdk/src/share/native/sun/awt/image/gif/gifdecoder.c	Tue Nov 12 11:32:48 2013 +0400
+++ b/jdk/src/share/native/sun/awt/image/gif/gifdecoder.c	Fri Dec 20 09:58:29 2013 -0800
@@ -249,6 +249,7 @@
                 /* fill the block */
                 len = (*env)->CallIntMethod(env, this, readID,
                                             blockh, remain, blockLength + 1);
+                if (len > blockLength + 1) len = blockLength + 1;
                 if ((*env)->ExceptionOccurred(env)) {
                     return 0;
                 }
--- a/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c	Tue Nov 12 11:32:48 2013 +0400
+++ b/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c	Fri Dec 20 09:58:29 2013 -0800
@@ -945,6 +945,7 @@
                                 JPEGImageReader_readInputDataID,
                                 sb->hstreamBuffer, 0,
                                 sb->bufferLength);
+    if (ret > sb->bufferLength) ret = sb->bufferLength;
     if ((*env)->ExceptionOccurred(env)
         || !GET_ARRAYS(env, data, &(src->next_input_byte))) {
             cinfo->err->error_exit((j_common_ptr) cinfo);
@@ -1041,6 +1042,7 @@
                                 JPEGImageReader_readInputDataID,
                                 sb->hstreamBuffer,
                                 offset, buflen);
+    if (ret > buflen) ret = buflen;
     if ((*env)->ExceptionOccurred(env)
         || !GET_ARRAYS(env, data, &(src->next_input_byte))) {
         cinfo->err->error_exit((j_common_ptr) cinfo);
--- a/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c	Tue Nov 12 11:32:48 2013 +0400
+++ b/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c	Fri Dec 20 09:58:29 2013 -0800
@@ -289,6 +289,7 @@
     buflen = (*env)->GetArrayLength(env, src->hInputBuffer);
     ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_readID,
                                 src->hInputBuffer, 0, buflen);
+    if (ret > buflen) ret = buflen;
     if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) {
         cinfo->err->error_exit((struct jpeg_common_struct *) cinfo);
     }
@@ -349,6 +350,7 @@
     }
     ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_readID,
                                 src->hInputBuffer, offset, buflen);
+    if (ret > buflen) ret = buflen;
     if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) {
         cinfo->err->error_exit((struct jpeg_common_struct *) cinfo);
     }
@@ -424,6 +426,7 @@
         ret = (*env)->CallIntMethod(env, src->hInputStream,
                                     InputStream_readID,
                                     src->hInputBuffer, 0, buflen);
+        if (ret > buflen) ret = buflen;
         if ((*env)->ExceptionOccurred(env)) {
             cinfo->err->error_exit((struct jpeg_common_struct *) cinfo);
         }