changeset 1057:ce39f16484d4

Fix 6804996.
author andrew
date Tue, 14 Apr 2009 16:42:04 +0100
parents f3c604b958f8
children 12cbd2b4b7b5
files src/share/native/sun/awt/splashscreen/splashscreen_impl.h src/share/native/sun/awt/splashscreen/splashscreen_png.c
diffstat 2 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/sun/awt/splashscreen/splashscreen_impl.h	Tue Apr 14 16:41:11 2009 +0100
+++ b/src/share/native/sun/awt/splashscreen/splashscreen_impl.h	Tue Apr 14 16:42:04 2009 +0100
@@ -155,6 +155,10 @@
 
 void SplashInitFrameShape(Splash * splash, int imageIndex);
 
+#define SAFE_TO_ALLOC(c, sz)                                               \
+    (((c) > 0) && ((sz) > 0) &&                                            \
+     ((0xffffffffu / ((unsigned int)(c))) > (unsigned int)(sz)))
+
 #define dbgprintf printf
 
 #endif
--- a/src/share/native/sun/awt/splashscreen/splashscreen_png.c	Tue Apr 14 16:41:11 2009 +0100
+++ b/src/share/native/sun/awt/splashscreen/splashscreen_png.c	Tue Apr 14 16:42:04 2009 +0100
@@ -103,9 +103,17 @@
 
     rowbytes = png_get_rowbytes(png_ptr, info_ptr);
 
+    if (!SAFE_TO_ALLOC(rowbytes, height)) {
+        goto done;
+    }
+
     if ((image_data = (unsigned char *) malloc(rowbytes * height)) == NULL) {
         goto done;
     }
+
+    if (!SAFE_TO_ALLOC(height, sizeof(png_bytep))) {
+        goto done;
+    }
     if ((row_pointers = (png_bytepp) malloc(height * sizeof(png_bytep)))
             == NULL) {
         goto done;
@@ -121,13 +129,28 @@
     splash->width = width;
     splash->height = height;
 
+    if (!SAFE_TO_ALLOC(splash->width, splash->imageFormat.depthBytes)) {
+        goto done;
+    }
     stride = splash->width * splash->imageFormat.depthBytes;
 
+    if (!SAFE_TO_ALLOC(splash->height, stride)) {
+        goto done;
+    }
     splash->frameCount = 1;
     splash->frames = (SplashImage *)
         malloc(sizeof(SplashImage) * splash->frameCount);
+
+    if (splash->frames == NULL) {
+        goto done;
+    }
+
     splash->loopCount = 1;
     splash->frames[0].bitmapBits = malloc(stride * splash->height);
+    if (splash->frames[0].bitmapBits == NULL) {
+        free(splash->frames);
+        goto done;
+    }
     splash->frames[0].delay = 0;
 
     /* FIXME: sort out the real format */