8139017: More stable image decoding
authorvadim
Fri, 16 Oct 2015 14:12:35 +0300
changeset 35289 1031cb912792
parent 35288 d4d492397105
child 35290 e50a5c5c6a47
8139017: More stable image decoding Reviewed-by: prr, serb, mschoene
jdk/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c
--- a/jdk/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c	Tue Oct 06 09:20:12 2015 +0200
+++ b/jdk/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c	Fri Oct 16 14:12:35 2015 +0300
@@ -180,6 +180,7 @@
       int               *ip;
       unsigned char     *bp;
   } outbuf;
+  size_t outbufSize;
   jobject hOutputBuffer;
 };
 
@@ -235,6 +236,7 @@
         assert(src->outbuf.ip == 0);
         src->outbuf.ip = (int *)(*env)->GetPrimitiveArrayCritical
             (env, src->hOutputBuffer, 0);
+        src->outbufSize = (*env)->GetArrayLength(env, src->hOutputBuffer);
         if (src->outbuf.ip == 0) {
             RELEASE_ARRAYS(env, src);
             return 0;
@@ -677,8 +679,8 @@
                                               cinfo.output_scanline - 1);
           } else {
               if (hasalpha) {
-                  ip = jsrc.outbuf.ip + cinfo.image_width;
-                  bp = jsrc.outbuf.bp + cinfo.image_width * 4;
+                  ip = jsrc.outbuf.ip + jsrc.outbufSize;
+                  bp = jsrc.outbuf.bp + jsrc.outbufSize * 4;
                   while (ip > jsrc.outbuf.ip) {
                       pixel = (*--bp) << 24;
                       pixel |= (*--bp);
@@ -687,8 +689,8 @@
                       *--ip = pixel;
                   }
               } else {
-                  ip = jsrc.outbuf.ip + cinfo.image_width;
-                  bp = jsrc.outbuf.bp + cinfo.image_width * 3;
+                  ip = jsrc.outbuf.ip + jsrc.outbufSize;
+                  bp = jsrc.outbuf.bp + jsrc.outbufSize * 3;
                   while (ip > jsrc.outbuf.ip) {
                       pixel = (*--bp);
                       pixel |= (*--bp) << 8;