changeset 1175:7f6c1ce75629

6804998: JRE GIF Decoding Heap Corruption [V-y6g5jlm8e1] Reviewed-by: prr
author bae
date Thu, 05 Mar 2009 19:36:51 +0300
parents dedf9366f289
children 51f13571014c
files src/share/classes/sun/awt/image/GifImageDecoder.java src/share/native/sun/awt/image/gif/gifdecoder.c
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/awt/image/GifImageDecoder.java	Tue Mar 03 16:10:37 2009 -0800
+++ b/src/share/classes/sun/awt/image/GifImageDecoder.java	Thu Mar 05 19:36:51 2009 +0300
@@ -585,9 +585,16 @@
             System.out.print("Reading a " + width + " by " + height + " " +
                       (interlace ? "" : "non-") + "interlaced image...");
         }
-
+        int initCodeSize = ExtractByte(block, 9);
+        if (initCodeSize >= 12) {
+            if (verbose) {
+                System.out.println("Invalid initial code size: " +
+                                   initCodeSize);
+            }
+            return false;
+        }
         boolean ret = parseImage(x, y, width, height,
-                                 interlace, ExtractByte(block, 9),
+                                 interlace, initCodeSize,
                                  block, rasline, model);
 
         if (!ret) {
--- a/src/share/native/sun/awt/image/gif/gifdecoder.c	Tue Mar 03 16:10:37 2009 -0800
+++ b/src/share/native/sun/awt/image/gif/gifdecoder.c	Thu Mar 05 19:36:51 2009 +0300
@@ -191,6 +191,11 @@
     int passht = passinc;
     int len;
 
+    /* We have verified the initial code size on the java layer.
+     * Here we just check bounds for particular indexes. */
+    if (freeCode >= 4096 || maxCode >= 4096) {
+        return 0;
+    }
     if (blockh == 0 || raslineh == 0
         || prefixh == 0 || suffixh == 0
         || outCodeh == 0)