OpenPKG CVS Repository
  http://cvs.openpkg.org/
  ____________________________________________________________________________

  Server: cvs.openpkg.org                  Name:   Ralf S. Engelschall
  Root:   /e/openpkg/cvs                   Email:  [EMAIL PROTECTED]
  Module: openpkg-src                      Date:   30-Oct-2004 13:17:25
  Branch: OPENPKG_2_1_SOLID                Handle: 2004103012172400

  Modified files:           (Branch: OPENPKG_2_1_SOLID)
    openpkg-src/gd          gd.patch gd.spec

  Log:
    Fix Security Bugs (OpenPKG-SA-2004.049-gd, CAN-2004-0990)

  Summary:
    Revision    Changes     Path
    1.2.4.1     +260 -0     openpkg-src/gd/gd.patch
    1.72.2.3    +1  -1      openpkg-src/gd/gd.spec
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: openpkg-src/gd/gd.patch
  ============================================================================
  $ cvs diff -u -r1.2 -r1.2.4.1 gd.patch
  --- openpkg-src/gd/gd.patch   25 Dec 2003 08:57:39 -0000      1.2
  +++ openpkg-src/gd/gd.patch   30 Oct 2004 11:17:24 -0000      1.2.4.1
  @@ -82,3 +82,263 @@
    #include <pthread.h>
    #define gdMutexDeclare(x) pthread_mutex_t x
    #define gdMutexSetup(x) pthread_mutex_init(&x, 0)
  +
  +-----------------------------------------------------------------------------
  +
  +Fix Security Bugs (OpenPKG-SA-2004.049-gd, CAN-2004-0990)
  +
  +Integer overflow allows remote attackers to cause a Denial of Service
  +(DoS) and possibly execute arbitrary code via PNG image files with large
  +image rows values that lead to a heap-based buffer overflow in the
  +gdImageCreateFromPngCtx() function.
  +
  +Index: gd.c
  +--- gd.c.orig        2004-07-01 23:30:30 +0200
  ++++ gd.c     2004-10-30 13:12:02 +0200
  +@@ -2064,6 +2064,12 @@
  +   /* We only need to use floating point to determine the correct
  +      stretch vector for one line's worth. */
  +   double accum;
  ++  if (gd_overflow2(sizeof (int), srcW)) {
  ++    return;
  ++  }
  ++  if (gd_overflow2(sizeof (int), srcH)) {
  ++    return;
  ++  }
  +   stx = (int *) gdMalloc (sizeof (int) * srcW);
  +   sty = (int *) gdMalloc (sizeof (int) * srcH);
  +   accum = 0;
  +@@ -2570,6 +2576,9 @@
  + 
  +   if (!im->polyAllocated)
  +     {
  ++      if (gd_overflow2(sizeof (int), n)) {
  ++        return;
  ++      }
  +       im->polyInts = (int *) gdMalloc (sizeof (int) * n);
  +       im->polyAllocated = n;
  +     }
  +@@ -2683,7 +2692,7 @@
  +     {
  +           int minx = im->polyInts[i];
  +           int maxx = im->polyInts[i + 1];
  +-          horizontalLine(im, minx, maxx, y, fill_color);
  ++          gdImageLine (im, im->polyInts[i], y, im->polyInts[i + 1], y, fill_color);
  +     }
  +     }
  +   /* If we are drawing this AA, then redraw the border with AA lines. */
  +@@ -2693,6 +2702,7 @@
  +   } 
  + }
  + 
  ++#if 0
  + static void horizontalLine(gdImagePtr im, int minx, int maxx, int y,
  +     int fill_color)
  + {
  +@@ -2715,6 +2725,7 @@
  +     }
  +   }
  + }
  ++#endif
  + 
  + inline static void gdImageSetAAPixelColor(gdImagePtr im, int x, int y, int color, 
int t);
  + 
  +@@ -2724,6 +2735,9 @@
  +     {
  +       gdFree (im->style);
  +     }
  ++  if (gd_overflow2(sizeof (int), noOfPixels)) {
  ++    return;
  ++  }         
  +   im->style = (int *) gdMalloc (sizeof (int) * noOfPixels);
  +   memcpy (im->style, style, sizeof (int) * noOfPixels);
  +   im->styleLength = noOfPixels;
  +Index: gd_io_dp.c
  +--- gd_io_dp.c.orig  2004-05-24 16:49:46 +0200
  ++++ gd_io_dp.c       2004-10-30 13:12:02 +0200
  +@@ -199,6 +199,9 @@
  +     {
  +       return FALSE;
  +     }
  ++      if (gd_overflow2(dp->realSize, 2)) {
  ++        return FALSE;
  ++      }
  +       if (!gdReallocDynamic (dp, dp->realSize * 2))
  +     {
  +       dp->dataGood = FALSE;
  +@@ -375,6 +378,9 @@
  +     {
  +       return FALSE;
  +     }
  ++      if (gd_overflow2(dp->realSize, 2)) {
  ++        return FALSE;
  ++      }
  +       if (!gdReallocDynamic (dp, bytesNeeded * 2))
  +     {
  +       dp->dataGood = FALSE;
  +Index: gd_png.c
  +--- gd_png.c.orig    2004-05-24 16:42:18 +0200
  ++++ gd_png.c 2004-10-30 13:12:02 +0200
  +@@ -312,12 +312,21 @@
  + 
  +   /* allocate space for the PNG image data */
  +   rowbytes = png_get_rowbytes (png_ptr, info_ptr);
  ++  if (gd_overflow2(rowbytes, height)) {
  ++    png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
  ++    return NULL;
  ++  }  
  +   if ((image_data = (png_bytep) gdMalloc (rowbytes * height)) == NULL)
  +     {
  +       fprintf (stderr, "gd-png error: cannot allocate image data\n");
  +       png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
  +       return NULL;
  +     }
  ++  if (gd_overflow2(height, sizeof (png_bytep))) {
  ++    png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
  ++    gdFree (image_data);
  ++    return NULL;
  ++  }    
  +   if ((row_pointers =
  +        (png_bytepp) gdMalloc (height * sizeof (png_bytep))) == NULL)
  +     {
  +@@ -715,20 +724,25 @@
  +       int thisPixel;
  +       png_bytep *prow_pointers;
  +       int saveAlphaFlag = im->saveAlphaFlag;
  ++      if (gd_overflow2(sizeof (png_bytep), height)) {
  ++        return;
  ++      } 
  +       row_pointers = gdMalloc (sizeof (png_bytep) * height);
  +       if (row_pointers == NULL)
  +     {
  +       fprintf (stderr, "gd-png error: unable to allocate row_pointers\n");
  ++          return;
  +     }
  +       prow_pointers = row_pointers;
  +       for (j = 0; j < height; ++j)
  +     {
  +-      if ((*prow_pointers =
  +-           (png_bytep) gdMalloc (width * channels)) == NULL)
  ++          if (gd_overflow2(width, channels) || ((*prow_pointers =
  ++           (png_bytep) gdMalloc (width * channels)) == NULL))
  +         {
  +           fprintf (stderr, "gd-png error: unable to allocate rows\n");
  +           for (i = 0; i < j; ++i)
  +             gdFree (row_pointers[i]);
  ++              free(row_pointers);
  +           return;
  +         }
  +       pOutputRow = *prow_pointers++;
  +@@ -766,11 +780,15 @@
  +       if (remap)
  +     {
  +       png_bytep *row_pointers;
  ++          if (gd_overflow2(sizeof (png_bytep), height)) {
  ++            return;
  ++          }
  +       row_pointers = gdMalloc (sizeof (png_bytep) * height);
  +       if (row_pointers == NULL)
  +         {
  +           fprintf (stderr,
  +                    "gd-png error: unable to allocate row_pointers\n");
  ++              return;
  +         }
  +       for (j = 0; j < height; ++j)
  +         {
  +@@ -779,6 +797,7 @@
  +               fprintf (stderr, "gd-png error: unable to allocate rows\n");
  +               for (i = 0; i < j; ++i)
  +                 gdFree (row_pointers[i]);
  ++              gdFree (row_pointers);
  +               return;
  +             }
  +           for (i = 0; i < width; ++i)
  +Index: gd_topal.c
  +--- gd_topal.c.orig  2004-07-21 16:40:08 +0200
  ++++ gd_topal.c       2004-10-30 13:12:02 +0200
  +@@ -793,6 +793,9 @@
  +   boxlist = (boxptr) (*cinfo->mem->alloc_small)
  +     ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF (box));
  + #else
  ++  if (gd_overflow2(desired_colors, sizeof (box))) {
  ++    return;
  ++   }
  +   boxlist = (boxptr) gdMalloc (desired_colors * sizeof (box));
  + #endif
  +   /* Initialize one box containing whole space */
  +Index: gdhelpers.c
  +--- gdhelpers.c.orig 2004-05-24 16:43:10 +0200
  ++++ gdhelpers.c      2004-10-30 13:12:02 +0200
  +@@ -4,8 +4,10 @@
  + 
  + #include "gd.h"
  + #include "gdhelpers.h"
  ++#include <stdio.h>
  + #include <stdlib.h>
  + #include <string.h>
  ++#include <limits.h>
  + 
  + /* TBB: gd_strtok_r is not portable; provide an implementation */
  + 
  +@@ -97,3 +99,18 @@
  + {
  +   free (ptr);
  + }
  ++
  ++int gd_overflow2(int a, int b)
  ++{
  ++    if(a < 0 || b < 0) {
  ++            fprintf(stderr, "gd warning: one parameter to a memory allocation 
multiplication is negative, failing operation gracefully\n");
  ++            return 1;
  ++    }
  ++    if(b == 0)
  ++            return 0;
  ++    if(a > INT_MAX / b) {
  ++            fprintf(stderr, "gd warning: product of memory allocation 
multiplication would exceed INT_MAX, failing operation gracefully\n");
  ++            return 1;
  ++    }
  ++    return 0;
  ++}
  +Index: gdhelpers.h
  +--- gdhelpers.h.orig 2004-05-24 16:38:31 +0200
  ++++ gdhelpers.h      2004-10-30 13:12:39 +0200
  +@@ -16,6 +16,8 @@
  + void *gdMalloc (size_t size);
  + void *gdRealloc (void *ptr, size_t size);
  + 
  ++int gd_overflow2(int a, int b);
  ++
  + /* 2.0.16: portable mutex support for thread safety. */
  + 
  + #ifdef WIN32
  +Index: wbmp.c
  +--- wbmp.c.orig      2004-05-24 16:50:22 +0200
  ++++ wbmp.c   2004-10-30 13:12:02 +0200
  +@@ -119,6 +119,14 @@
  +   if ((wbmp = (Wbmp *) gdMalloc (sizeof (Wbmp))) == NULL)
  +     return (NULL);
  + 
  ++  if (gd_overflow2(sizeof (int), width)) {
  ++    gdFree(wbmp);
  ++    return NULL;
  ++  }
  ++  if (gd_overflow2(sizeof (int) * width, height)) {
  ++    gdFree(wbmp);
  ++    return NULL;
  ++  }
  +   if ((wbmp->bitmap =
  +        (int *) gdMalloc (sizeof (int) * width * height)) == NULL)
  +     {
  +@@ -180,6 +188,12 @@
  +   printf ("W: %d, H: %d\n", wbmp->width, wbmp->height);
  + #endif
  + 
  ++  if (gd_overflow2(sizeof (int), wbmp->width) ||
  ++    gd_overflow2(sizeof (int) * wbmp->width, wbmp->height))
  ++    {
  ++      gdFree(wbmp);
  ++      return (-1);
  ++    }
  +   if ((wbmp->bitmap =
  +        (int *) gdMalloc (sizeof (int) * wbmp->width * wbmp->height)) == NULL)
  +     {
  @@ .
  patch -p0 <<'@@ .'
  Index: openpkg-src/gd/gd.spec
  ============================================================================
  $ cvs diff -u -r1.72.2.2 -r1.72.2.3 gd.spec
  --- openpkg-src/gd/gd.spec    25 Jul 2004 08:15:11 -0000      1.72.2.2
  +++ openpkg-src/gd/gd.spec    30 Oct 2004 11:17:24 -0000      1.72.2.3
  @@ -34,7 +34,7 @@
   Group:        Graphics
   License:      GPL
   Version:      2.0.27
  -Release:      2.1.1
  +Release:      2.1.2
   
   #   package options
   %option       with_xpm  no
  @@ .
______________________________________________________________________
The OpenPKG Project                                    www.openpkg.org
CVS Repository Commit List                     [EMAIL PROTECTED]

Reply via email to