Blame SOURCES/netpbm-security-code.patch

1ab173
diff -up netpbm-10.58.01/analyzer/pgmtexture.c.security-code netpbm-10.58.01/analyzer/pgmtexture.c
1ab173
--- netpbm-10.58.01/analyzer/pgmtexture.c.security-code	2012-04-09 15:31:32.000000000 +0200
1ab173
+++ netpbm-10.58.01/analyzer/pgmtexture.c	2012-04-09 15:40:03.183620040 +0200
1ab173
@@ -97,7 +97,7 @@ vector(unsigned int const nl,
1ab173
     float * v;
1ab173
 
1ab173
     assert(nh >= nl);
1ab173
-
1ab173
+    overflow_add(nh - nl, 1);
1ab173
     MALLOCARRAY(v, (unsigned) (nh - nl + 1));
1ab173
 
1ab173
     if (v == NULL)
1ab173
@@ -129,6 +129,7 @@ matrix (unsigned int const nrl,
1ab173
     assert(nrh >= nrl);
1ab173
 
1ab173
     /* allocate pointers to rows */
1ab173
+    overflow_add(nrh - nrl, 1);
1ab173
     MALLOCARRAY(m, (unsigned) (nrh - nrl + 1));
1ab173
     if (m == NULL)
1ab173
         pm_error("Unable to allocate memory for a matrix.");
1ab173
@@ -136,7 +137,7 @@ matrix (unsigned int const nrl,
1ab173
     m -= ncl;
1ab173
 
1ab173
     assert (nch >= ncl);
1ab173
-
1ab173
+    overflow_add(nch - ncl, 1);
1ab173
     /* allocate rows and set pointers to them */
1ab173
     for (i = nrl; i <= nrh; ++i) {
1ab173
         MALLOCARRAY(m[i], (unsigned) (nch - ncl + 1));
1ab173
diff -up netpbm-10.58.01/converter/other/gemtopnm.c.security-code netpbm-10.58.01/converter/other/gemtopnm.c
1ab173
--- netpbm-10.58.01/converter/other/gemtopnm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/gemtopnm.c	2012-04-09 15:40:03.183620040 +0200
1ab173
@@ -106,6 +106,7 @@ main(argc, argv)
1ab173
 
1ab173
 	pnm_writepnminit( stdout, cols, rows, MAXVAL, type, 0 );
1ab173
 
1ab173
+    overflow_add(cols, padright);
1ab173
     { 
1ab173
         /* allocate input row data structure */
1ab173
         int plane;
1ab173
diff -up netpbm-10.58.01/converter/other/jpegtopnm.c.security-code netpbm-10.58.01/converter/other/jpegtopnm.c
1ab173
--- netpbm-10.58.01/converter/other/jpegtopnm.c.security-code	2012-04-09 15:31:40.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/jpegtopnm.c	2012-04-09 15:40:03.184620028 +0200
1ab173
@@ -861,6 +861,8 @@ convertImage(FILE *
1ab173
     /* Calculate output image dimensions so we can allocate space */
1ab173
     jpeg_calc_output_dimensions(cinfoP);
1ab173
 
1ab173
+    overflow2(cinfoP->output_width, cinfoP->output_components);
1ab173
+
1ab173
     /* Start decompressor */
1ab173
     jpeg_start_decompress(cinfoP);
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/other/pbmtopgm.c.security-code netpbm-10.58.01/converter/other/pbmtopgm.c
1ab173
--- netpbm-10.58.01/converter/other/pbmtopgm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/pbmtopgm.c	2012-04-09 15:40:03.184620028 +0200
1ab173
@@ -47,6 +47,7 @@ main(int argc, char *argv[]) {
1ab173
                  "than the image height (%u rows)", height, rows);
1ab173
 
1ab173
     outrow = pgm_allocrow(cols) ;
1ab173
+    overflow2(width, height);
1ab173
     maxval = MIN(PGM_OVERALLMAXVAL, width*height);
1ab173
     pgm_writepgminit(stdout, cols, rows, maxval, 0) ;
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/other/pnmtoddif.c.security-code netpbm-10.58.01/converter/other/pnmtoddif.c
1ab173
--- netpbm-10.58.01/converter/other/pnmtoddif.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/pnmtoddif.c	2012-04-09 15:40:03.185620015 +0200
1ab173
@@ -632,6 +632,7 @@ main(int argc, char *argv[]) {
1ab173
     switch (PNM_FORMAT_TYPE(format)) {
1ab173
     case PBM_TYPE:
1ab173
         ip.bits_per_pixel = 1;
1ab173
+        overflow_add(cols, 7);
1ab173
         ip.bytes_per_line = (cols + 7) / 8;
1ab173
         ip.spectral = 2;
1ab173
         ip.components = 1;
1ab173
@@ -647,6 +648,7 @@ main(int argc, char *argv[]) {
1ab173
         ip.polarity = 2;
1ab173
         break;
1ab173
     case PPM_TYPE:
1ab173
+        overflow2(cols, 3);
1ab173
         ip.bytes_per_line = 3 * cols;
1ab173
         ip.bits_per_pixel = 24;
1ab173
         ip.spectral = 5;
1ab173
diff -up netpbm-10.58.01/converter/other/pnmtojpeg.c.security-code netpbm-10.58.01/converter/other/pnmtojpeg.c
1ab173
--- netpbm-10.58.01/converter/other/pnmtojpeg.c.security-code	2012-04-09 15:31:39.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/pnmtojpeg.c	2012-04-09 15:40:03.186620002 +0200
1ab173
@@ -605,7 +605,11 @@ read_scan_script(j_compress_ptr const ci
1ab173
            want JPOOL_PERMANENT.  
1ab173
         */
1ab173
         const unsigned int scan_info_size = nscans * sizeof(jpeg_scan_info);
1ab173
-        jpeg_scan_info * const scan_info = 
1ab173
+        const jpeg_scan_info * scan_info;
1ab173
+      
1ab173
+        overflow2(nscans, sizeof(jpeg_scan_info));
1ab173
+      
1ab173
+        scan_info =
1ab173
             (jpeg_scan_info *)
1ab173
             (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
1ab173
                                         scan_info_size);
1ab173
@@ -937,6 +941,8 @@ compute_rescaling_array(JSAMPLE ** const
1ab173
   const long half_maxval = maxval / 2;
1ab173
   long val;
1ab173
 
1ab173
+  overflow_add(maxval, 1);
1ab173
+  overflow2(maxval+1, sizeof(JSAMPLE));
1ab173
   *rescale_p = (JSAMPLE *)
1ab173
     (cinfo.mem->alloc_small) ((j_common_ptr) &cinfo, JPOOL_IMAGE,
1ab173
                               (size_t) (((long) maxval + 1L) * 
1ab173
@@ -1015,6 +1021,7 @@ convert_scanlines(struct jpeg_compress_s
1ab173
     */
1ab173
 
1ab173
   /* Allocate the libpnm output and compressor input buffers */
1ab173
+  overflow2(cinfo_p->image_width, cinfo_p->input_components);
1ab173
   buffer = (*cinfo_p->mem->alloc_sarray)
1ab173
     ((j_common_ptr) cinfo_p, JPOOL_IMAGE,
1ab173
      (unsigned int) cinfo_p->image_width * cinfo_p->input_components, 
1ab173
diff -up netpbm-10.58.01/converter/other/pnmtops.c.security-code netpbm-10.58.01/converter/other/pnmtops.c
1ab173
--- netpbm-10.58.01/converter/other/pnmtops.c.security-code	2012-04-09 15:31:40.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/pnmtops.c	2012-04-09 15:40:03.187619989 +0200
1ab173
@@ -256,17 +256,21 @@ parseCommandLine(int argc, const char **
1ab173
     validateCompDimension(width, 72, "-width value");
1ab173
     validateCompDimension(height, 72, "-height value");
1ab173
     
1ab173
+    overflow2(width, 72);
1ab173
     cmdlineP->width  = width * 72;
1ab173
+    overflow2(height, 72);
1ab173
     cmdlineP->height = height * 72;
1ab173
 
1ab173
     if (imagewidthSpec) {
1ab173
         validateCompDimension(imagewidth, 72, "-imagewidth value");
1ab173
+        overflow2(imagewidth, 72);
1ab173
         cmdlineP->imagewidth = imagewidth * 72;
1ab173
     }
1ab173
     else
1ab173
         cmdlineP->imagewidth = 0;
1ab173
     if (imageheightSpec) {
1ab173
-        validateCompDimension(imagewidth, 72, "-imageheight value");
1ab173
+        validateCompDimension(imageheight, 72, "-imageheight value");
1ab173
+        overflow2(imageheight, 72);
1ab173
         cmdlineP->imageheight = imageheight * 72;
1ab173
     }
1ab173
     else
1ab173
diff -up netpbm-10.58.01/converter/other/pnmtorle.c.security-code netpbm-10.58.01/converter/other/pnmtorle.c
1ab173
--- netpbm-10.58.01/converter/other/pnmtorle.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/pnmtorle.c	2012-04-09 15:40:03.188619976 +0200
1ab173
@@ -19,6 +19,8 @@
1ab173
  * If you modify this software, you should include a notice giving the
1ab173
  * name of the person performing the modification, the date of modification,
1ab173
  * and the reason for such modification.
1ab173
+ *
1ab173
+ *  2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
1ab173
  */
1ab173
 /*
1ab173
  * pnmtorle - A program which will convert pbmplus (ppm or pgm) images
1ab173
diff -up netpbm-10.58.01/converter/other/pnmtosgi.c.security-code netpbm-10.58.01/converter/other/pnmtosgi.c
1ab173
--- netpbm-10.58.01/converter/other/pnmtosgi.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/pnmtosgi.c	2012-04-09 15:40:03.188619976 +0200
1ab173
@@ -254,6 +254,7 @@ build_channels(FILE * const ifp, int con
1ab173
 #endif
1ab173
 
1ab173
     if( storage != STORAGE_VERBATIM ) {
1ab173
+        overflow2(channels, rows);
1ab173
         MALLOCARRAY_NOFAIL(table, channels * rows);
1ab173
         MALLOCARRAY_NOFAIL(rletemp, WORSTCOMPR(cols));
1ab173
     }
1ab173
@@ -306,6 +307,8 @@ compress(ScanElem * temp,
1ab173
             break;
1ab173
         case STORAGE_RLE:
1ab173
             tabrow = chan_no * rows + row;
1ab173
+            overflow2(chan_no, rows);
1ab173
+            overflow_add(chan_no* rows, row);
1ab173
             len = rle_compress(temp, cols);    /* writes result into rletemp */
1ab173
             channel[chan_no][row].length = len;
1ab173
             MALLOCARRAY(p, len);
1ab173
diff -up netpbm-10.58.01/converter/other/rletopnm.c.security-code netpbm-10.58.01/converter/other/rletopnm.c
1ab173
--- netpbm-10.58.01/converter/other/rletopnm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/rletopnm.c	2012-04-09 15:40:03.189619963 +0200
1ab173
@@ -19,6 +19,8 @@
1ab173
  * If you modify this software, you should include a notice giving the
1ab173
  * name of the person performing the modification, the date of modification,
1ab173
  * and the reason for such modification.
1ab173
+ *
1ab173
+ *  2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
1ab173
  */
1ab173
 /*
1ab173
  * rletopnm - A conversion program to convert from Utah's "rle" image format
1ab173
diff -up netpbm-10.58.01/converter/other/sgitopnm.c.security-code netpbm-10.58.01/converter/other/sgitopnm.c
1ab173
--- netpbm-10.58.01/converter/other/sgitopnm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/sgitopnm.c	2012-04-09 15:40:03.189619963 +0200
1ab173
@@ -359,10 +359,14 @@ readChannels(FILE *       const ifP,
1ab173
         MALLOCARRAY_NOFAIL(image, head->ysize);
1ab173
     } else {
1ab173
         maxchannel = MIN(3, head->zsize);
1ab173
+        overflow2(head->ysize, maxchannel);
1ab173
         MALLOCARRAY_NOFAIL(image, head->ysize * maxchannel);
1ab173
     }
1ab173
-    if (table) 
1ab173
+    if (table) {
1ab173
+        overflow2(head->xsize, 2);
1ab173
+        overflow_add(head->xsize*2, 2);
1ab173
         MALLOCARRAY_NOFAIL(temp, WORSTCOMPR(head->xsize));
1ab173
+    }
1ab173
 
1ab173
     for (channel = 0; channel < maxchannel; ++channel) {
1ab173
         unsigned int row;
1ab173
diff -up netpbm-10.58.01/converter/other/sirtopnm.c.security-code netpbm-10.58.01/converter/other/sirtopnm.c
1ab173
--- netpbm-10.58.01/converter/other/sirtopnm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/sirtopnm.c	2012-04-09 15:40:03.190619951 +0200
1ab173
@@ -69,6 +69,7 @@ char* argv[];
1ab173
 	    }
1ab173
 	    break;
1ab173
 	case PPM_TYPE:
1ab173
+	    overflow3(cols, rows, 3);
1ab173
 	    picsize = cols * rows * 3;
1ab173
 	    planesize = cols * rows;
1ab173
             if ( !( sirarray = (unsigned char*) malloc( picsize ) ) ) 
1ab173
diff -up netpbm-10.58.01/converter/other/tifftopnm.c.security-code netpbm-10.58.01/converter/other/tifftopnm.c
1ab173
--- netpbm-10.58.01/converter/other/tifftopnm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/tifftopnm.c	2012-04-09 15:40:03.191619939 +0200
1ab173
@@ -1279,7 +1279,9 @@ convertRasterByRows(pnmOut *       const
1ab173
     if (scanbuf == NULL)
1ab173
         pm_error("can't allocate memory for scanline buffer");
1ab173
 
1ab173
-    MALLOCARRAY(samplebuf, cols * spp);
1ab173
+    /* samplebuf is unsigned int * !!! */
1ab173
+    samplebuf = (unsigned int *) malloc3(cols , sizeof(unsigned int) , spp);
1ab173
+
1ab173
     if (samplebuf == NULL)
1ab173
         pm_error("can't allocate memory for row buffer");
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/other/xwdtopnm.c.security-code netpbm-10.58.01/converter/other/xwdtopnm.c
1ab173
--- netpbm-10.58.01/converter/other/xwdtopnm.c.security-code	2012-04-09 15:31:40.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/other/xwdtopnm.c	2012-04-09 15:40:03.192619927 +0200
1ab173
@@ -209,6 +209,10 @@ processX10Header(X10WDFileHeader *  cons
1ab173
         *colorsP = pnm_allocrow(2);
1ab173
         PNM_ASSIGN1((*colorsP)[0], 0);
1ab173
         PNM_ASSIGN1((*colorsP)[1], *maxvalP);
1ab173
+        overflow_add(h10P->pixmap_width, 15);
1ab173
+        if(h10P->pixmap_width < 0)
1ab173
+            pm_error("assert: negative width");
1ab173
+        overflow2((((h10P->pixmap_width + 15) / 16) * 16 - h10P->pixmap_width), 8);
1ab173
         *padrightP =
1ab173
             (((h10P->pixmap_width + 15) / 16) * 16 - h10P->pixmap_width) * 8;
1ab173
         *bits_per_itemP = 16;
1ab173
@@ -634,6 +638,7 @@ processX11Header(X11WDFileHeader *  cons
1ab173
 
1ab173
     *colsP = h11FixedP->pixmap_width;
1ab173
     *rowsP = h11FixedP->pixmap_height;
1ab173
+    overflow2(h11FixedP->bytes_per_line, 8);
1ab173
     *padrightP =
1ab173
         h11FixedP->bytes_per_line * 8 -
1ab173
         h11FixedP->pixmap_width * h11FixedP->bits_per_pixel;
1ab173
diff -up netpbm-10.58.01/converter/pbm/mdatopbm.c.security-code netpbm-10.58.01/converter/pbm/mdatopbm.c
1ab173
--- netpbm-10.58.01/converter/pbm/mdatopbm.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/mdatopbm.c	2012-04-09 15:40:03.192619927 +0200
1ab173
@@ -245,10 +245,13 @@ main(int argc, char **argv) {
1ab173
         pm_readlittleshort(infile, &yy;; nInCols = yy;
1ab173
     }
1ab173
     
1ab173
+    overflow2(nOutCols, 8);
1ab173
     nOutCols = 8 * nInCols;
1ab173
     nOutRows = nInRows;
1ab173
-    if (bScale) 
1ab173
+    if (bScale) {
1ab173
+        overflow2(nOutRows, 2);
1ab173
         nOutRows *= 2;
1ab173
+    }
1ab173
 
1ab173
     data = pbm_allocarray(nOutCols, nOutRows);
1ab173
     
1ab173
diff -up netpbm-10.58.01/converter/pbm/mgrtopbm.c.security-code netpbm-10.58.01/converter/pbm/mgrtopbm.c
1ab173
--- netpbm-10.58.01/converter/pbm/mgrtopbm.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/mgrtopbm.c	2012-04-09 15:40:03.193619915 +0200
1ab173
@@ -65,6 +65,8 @@ readMgrHeader(FILE *          const ifP,
1ab173
     if (head.h_high < ' ' || head.l_high < ' ')
1ab173
         pm_error("Invalid width field in MGR header");
1ab173
     
1ab173
+    overflow_add(*colsP, pad);
1ab173
+
1ab173
     *colsP = (((int)head.h_wide - ' ') << 6) + ((int)head.l_wide - ' ');
1ab173
     *rowsP = (((int)head.h_high - ' ') << 6) + ((int) head.l_high - ' ');
1ab173
     *padrightP = ( ( *colsP + pad - 1 ) / pad ) * pad - *colsP;
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtogem.c.security-code netpbm-10.58.01/converter/pbm/pbmtogem.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtogem.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtogem.c	2012-04-09 15:40:03.193619915 +0200
1ab173
@@ -79,6 +79,7 @@ putinit (int const rows, int const cols)
1ab173
   bitsperitem = 0;
1ab173
   bitshift = 7;
1ab173
   outcol = 0;
1ab173
+  overflow_add(cols, 7);
1ab173
   outmax = (cols + 7) / 8;
1ab173
   outrow = (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char));
1ab173
   lastrow = (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char));
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtogo.c.security-code netpbm-10.58.01/converter/pbm/pbmtogo.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtogo.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtogo.c	2012-04-09 15:40:03.193619915 +0200
1ab173
@@ -158,6 +158,7 @@ main(int           argc,
1ab173
     bitrow = pbm_allocrow(cols);
1ab173
 
1ab173
     /* Round cols up to the nearest multiple of 8. */
1ab173
+    overflow_add(cols, 7);
1ab173
     rucols = ( cols + 7 ) / 8;
1ab173
     bytesperrow = rucols;       /* GraphOn uses bytes */
1ab173
     rucols = rucols * 8;
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtolj.c.security-code netpbm-10.58.01/converter/pbm/pbmtolj.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtolj.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtolj.c	2012-04-09 15:40:03.194619902 +0200
1ab173
@@ -120,7 +120,11 @@ parseCommandLine(int argc, char ** argv,
1ab173
 static void
1ab173
 allocateBuffers(unsigned int const cols) {
1ab173
 
1ab173
+    overflow_add(cols, 8);
1ab173
     rowBufferSize = (cols + 7) / 8;
1ab173
+    overflow_add(rowBufferSize, 128);
1ab173
+    overflow_add(rowBufferSize, rowBufferSize+128);
1ab173
+    overflow_add(rowBufferSize+10, rowBufferSize/8);
1ab173
     packBufferSize = rowBufferSize + (rowBufferSize + 127) / 128 + 1;
1ab173
     deltaBufferSize = rowBufferSize + rowBufferSize / 8 + 10;
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtomacp.c.security-code netpbm-10.58.01/converter/pbm/pbmtomacp.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtomacp.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtomacp.c	2012-04-09 15:40:03.195619889 +0200
1ab173
@@ -101,6 +101,7 @@ char *argv[];
1ab173
   if( !lflg )
1ab173
     left = 0;
1ab173
 
1ab173
+  overflow_add(left, MAX_COLS - 1);
1ab173
   if( rflg )
1ab173
   { if( right - left >= MAX_COLS )
1ab173
       right = left + MAX_COLS - 1;
1ab173
@@ -111,6 +112,8 @@ char *argv[];
1ab173
   if( !tflg )
1ab173
     top = 0;
1ab173
 
1ab173
+  overflow_add(top, MAX_LINES - 1);
1ab173
+
1ab173
   if( bflg )
1ab173
   { if( bottom - top >= MAX_LINES )
1ab173
       bottom = top + MAX_LINES - 1;
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtomda.c.security-code netpbm-10.58.01/converter/pbm/pbmtomda.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtomda.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtomda.c	2012-04-09 15:40:03.195619889 +0200
1ab173
@@ -179,6 +179,7 @@ int main(int argc, char **argv)
1ab173
     
1ab173
     nOutRowsUnrounded = bScale ? nInRows/2 : nInRows;
1ab173
 
1ab173
+    overflow_add(nOutRowsUnrounded, 3);
1ab173
     nOutRows = ((nOutRowsUnrounded + 3) / 4) * 4;
1ab173
         /* MDA wants rows a multiple of 4 */   
1ab173
     nOutCols = nInCols / 8;
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtoppa/pbm.c.security-code netpbm-10.58.01/converter/pbm/pbmtoppa/pbm.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtoppa/pbm.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtoppa/pbm.c	2012-04-09 15:40:03.195619889 +0200
1ab173
@@ -105,6 +105,7 @@ int pbm_readline(pbm_stat* pbm,unsigned
1ab173
     return 0;
1ab173
 
1ab173
   case P4:
1ab173
+    overflow_add(pbm->width, 7);
1ab173
     tmp=(pbm->width+7)/8;
1ab173
     tmp2=fread(data,1,tmp,pbm->fptr);
1ab173
     if(tmp2 == tmp)
1ab173
@@ -129,7 +130,8 @@ void pbm_unreadline (pbm_stat *pbm, void
1ab173
     return;
1ab173
 
1ab173
   pbm->unread = 1;
1ab173
-  pbm->revdata = malloc ((pbm->width+7)/8);
1ab173
+  overflow_add(pbm->width, 7);
1ab173
+  pbm->revdata = malloc((pbm->width+7)/8);
1ab173
   memcpy (pbm->revdata, data, (pbm->width+7)/8);
1ab173
   pbm->current_line--;
1ab173
 }
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtoppa/pbmtoppa.c.security-code netpbm-10.58.01/converter/pbm/pbmtoppa/pbmtoppa.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtoppa/pbmtoppa.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtoppa/pbmtoppa.c	2012-04-09 15:40:03.196619876 +0200
1ab173
@@ -441,6 +441,7 @@ main(int argc, char *argv[]) {
1ab173
             pm_error("main(): unrecognized parameter '%s'", argv[argn]);
1ab173
     }
1ab173
 
1ab173
+    overflow_add(Width, 7);
1ab173
     Pwidth=(Width+7)/8;
1ab173
     printer.fptr=out;
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtoxbm.c.security-code netpbm-10.58.01/converter/pbm/pbmtoxbm.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtoxbm.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtoxbm.c	2012-04-09 15:40:03.196619876 +0200
1ab173
@@ -335,6 +335,8 @@ convertRaster(FILE *          const ifP,
1ab173
 
1ab173
     unsigned char * bitrow;
1ab173
     unsigned int row;
1ab173
+    
1ab173
+    overflow_add(cols, padright);
1ab173
 
1ab173
     putinit(xbmVersion);
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtoybm.c.security-code netpbm-10.58.01/converter/pbm/pbmtoybm.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtoybm.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtoybm.c	2012-04-09 15:40:03.197619863 +0200
1ab173
@@ -113,6 +113,7 @@ main(int argc, const char *argv[]) {
1ab173
     bitrow = pbm_allocrow(cols);
1ab173
     
1ab173
     /* Compute padding to round cols up to the nearest multiple of 16. */
1ab173
+    overflow_add(cols, 16);
1ab173
     padright = ((cols + 15) / 16) * 16 - cols;
1ab173
 
1ab173
     putinit(cols, rows);
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmtozinc.c.security-code netpbm-10.58.01/converter/pbm/pbmtozinc.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmtozinc.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmtozinc.c	2012-04-09 15:40:03.197619863 +0200
1ab173
@@ -65,6 +65,7 @@ main(int argc, char * argv[]) {
1ab173
     bitrow = pbm_allocrow( cols );
1ab173
 
1ab173
     /* Compute padding to round cols up to the nearest multiple of 16. */
1ab173
+    overflow_add(cols, 16);
1ab173
     padright = ( ( cols + 15 ) / 16 ) * 16 - cols;
1ab173
 
1ab173
     printf( "USHORT %s[] = {\n",name);
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmto10x.c.security-code netpbm-10.58.01/converter/pbm/pbmto10x.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmto10x.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmto10x.c	2012-04-09 15:40:03.197619863 +0200
1ab173
@@ -162,7 +162,7 @@ main(int argc, char * argv[]) {
1ab173
         res_60x72();
1ab173
 
1ab173
     pm_close(ifp);
1ab173
-    exit(0);
1ab173
+    return 0;
1ab173
 }
1ab173
 
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/pbm/pbmto4425.c.security-code netpbm-10.58.01/converter/pbm/pbmto4425.c
1ab173
--- netpbm-10.58.01/converter/pbm/pbmto4425.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pbmto4425.c	2012-04-09 15:40:03.198619851 +0200
1ab173
@@ -2,6 +2,7 @@
1ab173
 
1ab173
 #include "nstring.h"
1ab173
 #include "pbm.h"
1ab173
+#include <string.h>
1ab173
 
1ab173
 static char bit_table[2][3] = {
1ab173
 {1, 4, 0x10},
1ab173
@@ -160,7 +161,7 @@ main(int argc, char * argv[]) {
1ab173
     xres = vmap_width * 2;
1ab173
     yres = vmap_height * 3;
1ab173
 
1ab173
-    vmap = malloc(vmap_width * vmap_height * sizeof(char));
1ab173
+    vmap = malloc3(vmap_width, vmap_height, sizeof(char));
1ab173
     if(vmap == NULL)
1ab173
 	{
1ab173
         pm_error( "Cannot allocate memory" );
1ab173
diff -up netpbm-10.58.01/converter/pbm/pktopbm.c.security-code netpbm-10.58.01/converter/pbm/pktopbm.c
1ab173
--- netpbm-10.58.01/converter/pbm/pktopbm.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/pktopbm.c	2012-04-09 15:40:03.198619851 +0200
1ab173
@@ -277,6 +277,7 @@ main(int argc, char *argv[]) {
1ab173
         if (flagbyte == 7) {            /* long form preamble */
1ab173
             integer packetlength = get32() ;    /* character packet length */
1ab173
             car = get32() ;         /* character number */
1ab173
+            overflow_add(packetlength, pktopbm_pkloc);
1ab173
             endofpacket = packetlength + pktopbm_pkloc;
1ab173
                 /* calculate end of packet */
1ab173
             if ((car >= MAXPKCHAR) || !filename[car]) {
1ab173
diff -up netpbm-10.58.01/converter/pbm/thinkjettopbm.l.security-code netpbm-10.58.01/converter/pbm/thinkjettopbm.l
1ab173
--- netpbm-10.58.01/converter/pbm/thinkjettopbm.l.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/thinkjettopbm.l	2012-04-09 15:40:03.199619839 +0200
1ab173
@@ -114,7 +114,9 @@ DIG             [0-9]
1ab173
 <RASTERMODE>\033\*b{DIG}+W  {
1ab173
                             int l;
1ab173
                             if (rowCount >= rowCapacity) {
1ab173
+				overflow_add(rowCapacity, 100);
1ab173
                                 rowCapacity += 100;
1ab173
+				overflow2(rowCapacity, sizeof *rows);
1ab173
                                 rows = realloc (rows, rowCapacity * sizeof *rows);
1ab173
                                 if (rows == NULL)
1ab173
                                     pm_error ("Out of memory.");
1ab173
@@ -226,6 +228,8 @@ yywrap (void)
1ab173
     /*
1ab173
      * Quite simple since ThinkJet bit arrangement matches PBM
1ab173
      */
1ab173
+
1ab173
+    overflow2(maxRowLength, 8);
1ab173
     pbm_writepbminit(stdout, maxRowLength*8, rowCount, 0);
1ab173
 
1ab173
     packed_bitrow = malloc(maxRowLength);
1ab173
diff -up netpbm-10.58.01/converter/pbm/ybmtopbm.c.security-code netpbm-10.58.01/converter/pbm/ybmtopbm.c
1ab173
--- netpbm-10.58.01/converter/pbm/ybmtopbm.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pbm/ybmtopbm.c	2012-04-09 15:40:03.199619839 +0200
1ab173
@@ -49,6 +49,7 @@ getinit(FILE *  const ifP,
1ab173
         pm_error("EOF / read error");
1ab173
 
1ab173
     *depthP = 1;
1ab173
+    overflow_add(*colsP, 15);
1ab173
     *padrightP = ((*colsP + 15) / 16) * 16 - *colsP;
1ab173
 }
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/pgm/lispmtopgm.c.security-code netpbm-10.58.01/converter/pgm/lispmtopgm.c
1ab173
--- netpbm-10.58.01/converter/pgm/lispmtopgm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pgm/lispmtopgm.c	2012-04-09 15:40:03.199619839 +0200
1ab173
@@ -58,6 +58,7 @@ main( argc, argv )
1ab173
         pm_error( "depth (%d bits) is too large", depth);
1ab173
 
1ab173
     pgm_writepgminit( stdout, cols, rows, (gray) maxval, 0 );
1ab173
+    overflow_add(cols, 7);
1ab173
     grayrow = pgm_allocrow( ( cols + 7 ) / 8 * 8 );
1ab173
 
1ab173
     for ( row = 0; row < rows; ++row )
1ab173
@@ -102,7 +103,9 @@ getinit( file, colsP, rowsP, depthP, pad
1ab173
     
1ab173
     if ( *depthP == 0 )
1ab173
 	*depthP = 1;	/* very old file */
1ab173
-    
1ab173
+
1ab173
+    overflow_add((int)colsP, 31);
1ab173
+        
1ab173
     *padrightP = ( ( *colsP + 31 ) / 32 ) * 32 - *colsP;
1ab173
     
1ab173
     if ( *colsP != (cols_32 - *padrightP) ) {
1ab173
diff -up netpbm-10.58.01/converter/pgm/psidtopgm.c.security-code netpbm-10.58.01/converter/pgm/psidtopgm.c
1ab173
--- netpbm-10.58.01/converter/pgm/psidtopgm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/pgm/psidtopgm.c	2012-04-09 15:40:03.200619827 +0200
1ab173
@@ -78,6 +78,7 @@ main(int     argc,
1ab173
         pm_error("bits/sample (%d) is too large.", bitspersample);
1ab173
 
1ab173
     pgm_writepgminit(stdout, cols, rows, maxval, 0);
1ab173
+    overflow_add(cols, 7);
1ab173
     grayrow = pgm_allocrow((cols + 7) / 8 * 8);
1ab173
     for (row = 0; row < rows; ++row) {
1ab173
         unsigned int col;
1ab173
diff -up netpbm-10.58.01/converter/ppm/ilbmtoppm.c.security-code netpbm-10.58.01/converter/ppm/ilbmtoppm.c
1ab173
--- netpbm-10.58.01/converter/ppm/ilbmtoppm.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ilbmtoppm.c	2012-04-09 15:40:03.201619815 +0200
1ab173
@@ -592,6 +592,7 @@ decode_row(FILE *          const ifP,
1ab173
     rawtype *chp;
1ab173
 
1ab173
     cols = bmhdP->w;
1ab173
+    overflow_add(cols, 15);
1ab173
     bytes = RowBytes(cols);
1ab173
     for( plane = 0; plane < nPlanes; plane++ ) {
1ab173
         int mask;
1ab173
@@ -679,6 +680,23 @@ decode_mask(FILE *          const ifP,
1ab173
  Multipalette handling
1ab173
  ****************************************************************************/
1ab173
 
1ab173
+static void *
1ab173
+xmalloc2(x, y)
1ab173
+    int x;
1ab173
+    int y;
1ab173
+{
1ab173
+    void *mem;
1ab173
+
1ab173
+    overflow2(x,y);
1ab173
+    if( x * y == 0 )
1ab173
+        return NULL;
1ab173
+
1ab173
+    mem = malloc2(x,y);
1ab173
+    if( mem == NULL )
1ab173
+        pm_error("out of memory allocating %d bytes", x * y);
1ab173
+    return mem;
1ab173
+}
1ab173
+
1ab173
 
1ab173
 static void
1ab173
 multi_adjust(cmap, row, palchange)
1ab173
@@ -1341,6 +1359,9 @@ dcol_to_ppm(FILE *         const ifP,
1ab173
     if( redmaxval != maxval || greenmaxval != maxval || bluemaxval != maxval )
1ab173
         pm_message("scaling colors to %d bits", pm_maxvaltobits(maxval));
1ab173
     
1ab173
+    overflow_add(redmaxval, 1);
1ab173
+    overflow_add(greenmaxval, 1);
1ab173
+    overflow_add(bluemaxval, 1);
1ab173
     MALLOCARRAY_NOFAIL(redtable,   redmaxval   +1);
1ab173
     MALLOCARRAY_NOFAIL(greentable, greenmaxval +1);
1ab173
     MALLOCARRAY_NOFAIL(bluetable,  bluemaxval  +1);
1ab173
@@ -1763,7 +1784,9 @@ PCHG_ConvertSmall(PCHG, cmap, mask, data
1ab173
             ChangeCount32 = *data++;
1ab173
             datasize -= 2;
1ab173
 
1ab173
+            overflow_add(ChangeCount16, ChangeCount32);
1ab173
             changes = ChangeCount16 + ChangeCount32;
1ab173
+            overflow_add(changes, 1);
1ab173
             for( i = 0; i < changes; i++ ) {
1ab173
                 if( totalchanges >= PCHG->TotalChanges ) goto fail;
1ab173
                 if( datasize < 2 ) goto fail;
1ab173
@@ -2028,6 +2051,9 @@ read_pchg(FILE *     const ifp,
1ab173
             cmap->mp_change[i] = NULL;
1ab173
         if( PCHG.StartLine < 0 ) {
1ab173
             int nch;
1ab173
+            if(PCHG.MaxReg < PCHG.MinReg)
1ab173
+                pm_error("assert: MinReg > MaxReg");
1ab173
+            overflow_add(PCHG.MaxReg-PCHG.MinReg, 2);
1ab173
             nch = PCHG.MaxReg - PCHG.MinReg +1;
1ab173
             MALLOCARRAY_NOFAIL(cmap->mp_init, nch + 1);
1ab173
             for( i = 0; i < nch; i++ )
1ab173
@@ -2104,6 +2130,7 @@ process_body( FILE *          const ifp,
1ab173
     if( typeid == ID_ILBM ) {
1ab173
         int isdeep;
1ab173
 
1ab173
+        overflow_add(bmhdP->w, 15);
1ab173
         MALLOCARRAY_NOFAIL(ilbmrow, RowBytes(bmhdP->w));
1ab173
         *viewportmodesP |= fakeviewport;      /* -isham/-isehb */
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/ppm/imgtoppm.c.security-code netpbm-10.58.01/converter/ppm/imgtoppm.c
1ab173
--- netpbm-10.58.01/converter/ppm/imgtoppm.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/imgtoppm.c	2012-04-09 15:40:03.202619802 +0200
1ab173
@@ -84,6 +84,7 @@ main(int argc, char ** argv) {
1ab173
             len = atoi((char*) buf );
1ab173
             if ( fread( buf, len, 1, ifp ) != 1 )
1ab173
                 pm_error( "bad colormap buf" );
1ab173
+            overflow2(cmaplen, 3);
1ab173
             if ( cmaplen * 3 != len )
1ab173
             {
1ab173
                 pm_message(
1ab173
@@ -105,6 +106,7 @@ main(int argc, char ** argv) {
1ab173
                 pm_error( "bad pixel data header" );
1ab173
             buf[8] = '\0';
1ab173
             len = atoi((char*) buf );
1ab173
+            overflow2(cols, rows);
1ab173
             if ( len != cols * rows )
1ab173
                 pm_message(
1ab173
                     "pixel data length (%d) does not match image size (%d)",
1ab173
diff -up netpbm-10.58.01/converter/ppm/Makefile.security-code netpbm-10.58.01/converter/ppm/Makefile
1ab173
--- netpbm-10.58.01/converter/ppm/Makefile.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/Makefile	2012-04-09 15:40:03.202619802 +0200
1ab173
@@ -11,7 +11,7 @@ SUBDIRS = hpcdtoppm ppmtompeg
1ab173
 
1ab173
 PORTBINARIES =	411toppm eyuvtoppm gouldtoppm ilbmtoppm imgtoppm \
1ab173
 		leaftoppm mtvtoppm neotoppm \
1ab173
-		pcxtoppm pc1toppm pi1toppm picttoppm pjtoppm \
1ab173
+		pcxtoppm pc1toppm pi1toppm pjtoppm \
1ab173
 		ppmtoacad ppmtoapplevol ppmtoarbtxt ppmtoascii \
1ab173
 		ppmtobmp ppmtoeyuv ppmtogif ppmtoicr ppmtoilbm \
1ab173
 		ppmtoleaf ppmtolj ppmtomitsu ppmtoneo \
1ab173
diff -up netpbm-10.58.01/converter/ppm/pcxtoppm.c.security-code netpbm-10.58.01/converter/ppm/pcxtoppm.c
1ab173
--- netpbm-10.58.01/converter/ppm/pcxtoppm.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/pcxtoppm.c	2012-04-09 15:40:03.203619789 +0200
1ab173
@@ -409,6 +409,7 @@ pcx_planes_to_pixels(pixels, bitplanes,
1ab173
     /*
1ab173
      * clear the pixel buffer
1ab173
      */
1ab173
+    overflow2(bytesperline, 8);
1ab173
     npixels = (bytesperline * 8) / bitsperpixel;
1ab173
     p    = pixels;
1ab173
     while (--npixels >= 0)
1ab173
@@ -470,6 +471,7 @@ pcx_16col_to_ppm(FILE *       const ifP,
1ab173
     }
1ab173
 
1ab173
     /*  BytesPerLine should be >= BitsPerPixel * cols / 8  */
1ab173
+    overflow2(BytesPerLine, 8);
1ab173
     rawcols = BytesPerLine * 8 / BitsPerPixel;
1ab173
     if (headerCols > rawcols) {
1ab173
         pm_message("warning - BytesPerLine = %d, "
1ab173
diff -up netpbm-10.58.01/converter/ppm/picttoppm.c.security-code netpbm-10.58.01/converter/ppm/picttoppm.c
1ab173
--- netpbm-10.58.01/converter/ppm/picttoppm.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/picttoppm.c	2012-04-09 15:40:03.205619763 +0200
1ab173
@@ -1,3 +1,5 @@
1ab173
+#error "Unfixable. Don't ship me"
1ab173
+
1ab173
 /*
1ab173
  * picttoppm.c -- convert a MacIntosh PICT file to PPM format.
1ab173
  *
1ab173
diff -up netpbm-10.58.01/converter/ppm/pjtoppm.c.security-code netpbm-10.58.01/converter/ppm/pjtoppm.c
1ab173
--- netpbm-10.58.01/converter/ppm/pjtoppm.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/pjtoppm.c	2012-04-09 15:40:03.206619751 +0200
1ab173
@@ -127,19 +127,21 @@ main(argc, argv)
1ab173
                 case 'V':   /* send plane */
1ab173
                 case 'W':   /* send last plane */
1ab173
                     if (rows == -1 || r >= rows || image == NULL) {
1ab173
-                        if (rows == -1 || r >= rows)
1ab173
+                        if (rows == -1 || r >= rows) {
1ab173
+                            overflow_add(rows, 100);
1ab173
                             rows += 100;
1ab173
+                        }
1ab173
                         if (image == NULL) {
1ab173
-                            MALLOCARRAY(image, rows * planes);
1ab173
-                            MALLOCARRAY(imlen, rows * planes);
1ab173
+                            image = (unsigned char **)
1ab173
+                                malloc3(rows , planes , sizeof(unsigned char *));
1ab173
+                            imlen = (int *) malloc3(rows , planes,  sizeof(int));
1ab173
                         }
1ab173
                         else {
1ab173
+                            overflow2(rows,planes);
1ab173
                             image = (unsigned char **) 
1ab173
-                                realloc(image, 
1ab173
-                                        rows * planes * 
1ab173
+                                realloc2(image, rows * planes,
1ab173
                                         sizeof(unsigned char *));
1ab173
-                            imlen = (int *) 
1ab173
-                                realloc(imlen, rows * planes * sizeof(int));
1ab173
+                            imlen = (int *) realloc2(imlen, rows * planes, sizeof(int));
1ab173
                         }
1ab173
                     }
1ab173
                     if (image == NULL || imlen == NULL)
1ab173
@@ -212,8 +214,10 @@ main(argc, argv)
1ab173
                 for (i = 0, c = 0; c < imlen[p + r * planes]; c += 2)
1ab173
                     for (cmd = image[p + r * planes][c],
1ab173
                              val = image[p + r * planes][c+1]; 
1ab173
-                         cmd >= 0 && i < newcols; cmd--, i++) 
1ab173
+                         cmd >= 0 && i < newcols; cmd--, i++) {
1ab173
                         buf[i] = val;
1ab173
+                        overflow_add(i, 1);
1ab173
+                    }
1ab173
                 cols = cols > i ? cols : i;
1ab173
                 free(image[p + r * planes]);
1ab173
                 /* 
1ab173
@@ -224,6 +228,7 @@ main(argc, argv)
1ab173
                 image[p + r * planes] = (unsigned char *) realloc(buf, i);
1ab173
             }
1ab173
         }
1ab173
+        overflow2(cols, 8);
1ab173
         cols *= 8;
1ab173
     }
1ab173
             
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtoeyuv.c.security-code netpbm-10.58.01/converter/ppm/ppmtoeyuv.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtoeyuv.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtoeyuv.c	2012-04-09 15:40:03.206619751 +0200
1ab173
@@ -114,6 +114,7 @@ create_multiplication_tables(const pixva
1ab173
 
1ab173
     int index;
1ab173
 
1ab173
+    overflow_add(maxval, 1);
1ab173
     MALLOCARRAY_NOFAIL(mult299   , maxval+1);
1ab173
     MALLOCARRAY_NOFAIL(mult587   , maxval+1);
1ab173
     MALLOCARRAY_NOFAIL(mult114   , maxval+1);
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtoicr.c.security-code netpbm-10.58.01/converter/ppm/ppmtoicr.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtoicr.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtoicr.c	2012-04-09 15:40:03.207619739 +0200
1ab173
@@ -169,7 +169,7 @@ char* argv[];
1ab173
 
1ab173
 	if (rleflag) {	
1ab173
 		pm_message("sending run-length encoded picture data ..." );
1ab173
-		testimage = (char*) malloc(rows*cols);
1ab173
+		testimage = (char*) malloc2(rows, cols);
1ab173
 		p = testimage;
1ab173
 		for (i=0; i
1ab173
 			for (j=0; j
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtoilbm.c.security-code netpbm-10.58.01/converter/ppm/ppmtoilbm.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtoilbm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtoilbm.c	2012-04-09 15:40:03.208619727 +0200
1ab173
@@ -1220,6 +1220,7 @@ ppm_to_rgb8(ifP, cols, rows, maxval)
1ab173
 
1ab173
     maskmethod = 0;     /* no masking - RGB8 uses genlock bits */
1ab173
     compmethod = 4;     /* RGB8 files are always compressed */
1ab173
+    overflow2(cols, 4);
1ab173
     MALLOCARRAY_NOFAIL(compr_row, cols * 4);
1ab173
 
1ab173
     if( maxval != 255 ) {
1ab173
@@ -1308,6 +1309,7 @@ ppm_to_rgbn(ifP, cols, rows, maxval)
1ab173
 
1ab173
     maskmethod = 0;     /* no masking - RGBN uses genlock bits */
1ab173
     compmethod = 4;     /* RGBN files are always compressed */
1ab173
+    overflow2(cols, 2);
1ab173
     MALLOCARRAY_NOFAIL(compr_row, cols * 2);
1ab173
 
1ab173
     if( maxval != 15 ) {
1ab173
@@ -1785,6 +1787,7 @@ make_val_table(oldmaxval, newmaxval)
1ab173
     unsigned int i;
1ab173
     int * table;
1ab173
 
1ab173
+    overflow_add(oldmaxval, 1);
1ab173
     MALLOCARRAY_NOFAIL(table, oldmaxval + 1);
1ab173
     for (i = 0; i <= oldmaxval; ++i)
1ab173
         table[i] = ROUNDDIV(i * newmaxval, oldmaxval);
1ab173
@@ -2293,8 +2296,11 @@ main(int argc, char ** argv) {
1ab173
         MALLOCARRAY_NOFAIL(coded_rowbuf, RowBytes(cols));
1ab173
         for (i = 0; i < RowBytes(cols); ++i)
1ab173
             coded_rowbuf[i] = 0;
1ab173
-        if (DO_COMPRESS)
1ab173
+        if (DO_COMPRESS) {
1ab173
+            overflow2(cols,2);
1ab173
+            overflow_add(cols*2,2);
1ab173
             MALLOCARRAY_NOFAIL(compr_rowbuf, WORSTCOMPR(RowBytes(cols)));
1ab173
+	}
1ab173
     }
1ab173
     
1ab173
     switch (mode) {
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtolj.c.security-code netpbm-10.58.01/converter/ppm/ppmtolj.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtolj.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtolj.c	2012-04-09 15:40:03.210619701 +0200
1ab173
@@ -181,7 +181,8 @@ int main(int argc, char *argv[]) {
1ab173
 
1ab173
     ppm_readppminit( ifp, &cols, &rows, &maxval, &format );
1ab173
     pixelrow = ppm_allocrow( cols );
1ab173
-
1ab173
+    
1ab173
+    overflow2(cols, 6);
1ab173
     obuf = (unsigned char *) pm_allocrow(cols * 3, sizeof(unsigned char));
1ab173
     cbuf = (unsigned char *) pm_allocrow(cols * 6, sizeof(unsigned char));
1ab173
     if (mode == C_TRANS_MODE_DELTA)
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtomitsu.c.security-code netpbm-10.58.01/converter/ppm/ppmtomitsu.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtomitsu.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtomitsu.c	2012-04-09 15:40:03.210619702 +0200
1ab173
@@ -685,6 +685,8 @@ main(int argc, char * argv[]) {
1ab173
         medias = MSize_User;
1ab173
 
1ab173
     if (dpi300) {
1ab173
+        overflow2(medias.maxcols, 2);
1ab173
+        overflow2(medias.maxrows, 2);
1ab173
         medias.maxcols *= 2;
1ab173
         medias.maxrows *= 2;
1ab173
     }
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtopcx.c.security-code netpbm-10.58.01/converter/ppm/ppmtopcx.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtopcx.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtopcx.c	2012-04-09 15:40:03.210619702 +0200
1ab173
@@ -419,6 +419,8 @@ ppmTo16ColorPcx(pixel **            cons
1ab173
             else                   Planes = 1;
1ab173
         }
1ab173
     }
1ab173
+    overflow2(BitsPerPixel, cols);
1ab173
+    overflow_add(BitsPerPixel * cols, 7);
1ab173
     BytesPerLine = ((cols * BitsPerPixel) + 7) / 8;
1ab173
     MALLOCARRAY_NOFAIL(indexRow, cols);
1ab173
     MALLOCARRAY_NOFAIL(planesrow, BytesPerLine);
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtopict.c.security-code netpbm-10.58.01/converter/ppm/ppmtopict.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtopict.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtopict.c	2012-04-09 15:40:03.211619690 +0200
1ab173
@@ -441,6 +441,8 @@ main(int argc, const char ** argv) {
1ab173
     putShort(stdout, 0);            /* mode */
1ab173
 
1ab173
     /* Finally, write out the data. */
1ab173
+    overflow_add(cols/MAX_COUNT, 1);
1ab173
+    overflow_add(cols, cols/MAX_COUNT+1);
1ab173
     packed = malloc((unsigned)(cols+cols/MAX_COUNT+1));
1ab173
     for (row = 0, oc = 0; row < rows; row++)
1ab173
         oc += putRow(stdout, row, cols, pixels[row], packed);
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtopj.c.security-code netpbm-10.58.01/converter/ppm/ppmtopj.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtopj.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtopj.c	2012-04-09 15:40:03.212619677 +0200
1ab173
@@ -179,6 +179,7 @@ char *argv[];
1ab173
 	pixels = ppm_readppm( ifp, &cols, &rows, &maxval );
1ab173
 
1ab173
 	pm_close( ifp );
1ab173
+	overflow2(cols,2);
1ab173
 	obuf = (unsigned char *) pm_allocrow(cols, sizeof(unsigned char));
1ab173
 	cbuf = (unsigned char *) pm_allocrow(cols * 2, sizeof(unsigned char));
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtopjxl.c.security-code netpbm-10.58.01/converter/ppm/ppmtopjxl.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtopjxl.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtopjxl.c	2012-04-09 15:40:03.212619677 +0200
1ab173
@@ -276,6 +276,8 @@ main(int argc, const char * argv[]) {
1ab173
         pm_error("image too large; reduce with ppmscale");
1ab173
     if (maxval > PCL_MAXVAL)
1ab173
         pm_error("color range too large; reduce with ppmcscale");
1ab173
+    if (cols < 0 || rows < 0)
1ab173
+        pm_error("negative size is not possible");
1ab173
 
1ab173
     /* Figure out the colormap. */
1ab173
     pm_message("Computing colormap...");
1ab173
@@ -296,6 +298,8 @@ main(int argc, const char * argv[]) {
1ab173
         case 0: /* direct mode (no palette) */
1ab173
             bpp = bitsperpixel(maxval); /* bits per pixel */
1ab173
             bpg = bpp; bpb = bpp;
1ab173
+	    overflow2(bpp, 3);
1ab173
+	    overflow_add(bpp*3, 7);
1ab173
             bpp = (bpp*3+7)>>3;     /* bytes per pixel now */
1ab173
             bpr = (bpp<<3)-bpg-bpb; 
1ab173
             bpp *= cols;            /* bytes per row now */
1ab173
@@ -305,9 +309,13 @@ main(int argc, const char * argv[]) {
1ab173
         case 3: case 7: pclindex++;
1ab173
         default:
1ab173
             bpp = 8/pclindex;
1ab173
+	    overflow_add(cols, bpp);
1ab173
+	    if(bpp == 0)
1ab173
+		pm_error("assert: no bpp");
1ab173
             bpp = (cols+bpp-1)/bpp;      /* bytes per row */
1ab173
         }
1ab173
     }
1ab173
+    overflow2(bpp,2);
1ab173
     inrow = (char *)malloc((unsigned)bpp);
1ab173
     outrow = (char *)malloc((unsigned)bpp*2);
1ab173
     runcnt = (signed char *)malloc((unsigned)bpp);
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtowinicon.c.security-code netpbm-10.58.01/converter/ppm/ppmtowinicon.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtowinicon.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtowinicon.c	2012-04-09 15:40:03.213619664 +0200
1ab173
@@ -12,6 +12,7 @@
1ab173
 
1ab173
 #include <math.h>
1ab173
 #include <string.h>
1ab173
+#include <stdlib.h>
1ab173
 
1ab173
 #include "pm_c_util.h"
1ab173
 #include "winico.h"
1ab173
@@ -219,6 +220,7 @@ createAndBitmap (gray ** const ba, int c
1ab173
    MALLOCARRAY_NOFAIL(rowData, rows);
1ab173
    icBitmap->xBytes = xBytes;
1ab173
    icBitmap->data   = rowData;
1ab173
+   overflow2(xBytes, rows);
1ab173
    icBitmap->size   = xBytes * rows;
1ab173
    for (y=0;y
1ab173
       u1 * row;
1ab173
@@ -347,6 +349,7 @@ create4Bitmap (pixel ** const pa, int co
1ab173
    MALLOCARRAY_NOFAIL(rowData, rows);
1ab173
    icBitmap->xBytes = xBytes;
1ab173
    icBitmap->data   = rowData;
1ab173
+   overflow2(xBytes, rows);
1ab173
    icBitmap->size   = xBytes * rows;
1ab173
 
1ab173
    for (y=0;y
1ab173
@@ -407,6 +410,7 @@ create8Bitmap (pixel ** const pa, int co
1ab173
    MALLOCARRAY_NOFAIL(rowData, rows);
1ab173
    icBitmap->xBytes = xBytes;
1ab173
    icBitmap->data   = rowData;
1ab173
+   overflow2(xBytes, rows);
1ab173
    icBitmap->size   = xBytes * rows;
1ab173
 
1ab173
    for (y=0;y
1ab173
@@ -714,6 +718,10 @@ addEntryToIcon(MS_Ico       const MSIcon
1ab173
     entry->bitcount      = bpp;
1ab173
     entry->ih            = createInfoHeader(entry, xorBitmap, andBitmap);
1ab173
     entry->colors        = palette->colors;
1ab173
+    overflow2(4, entry->color_count);
1ab173
+    overflow_add(xorBitmap->size, andBitmap->size);
1ab173
+    overflow_add(xorBitmap->size + andBitmap->size, 40);
1ab173
+    overflow_add(xorBitmap->size + andBitmap->size + 40, 4 * entry->color_count);
1ab173
     entry->size_in_bytes = 
1ab173
         xorBitmap->size + andBitmap->size + 40 + (4 * entry->color_count);
1ab173
     if (verbose) 
1ab173
diff -up netpbm-10.58.01/converter/ppm/ppmtoxpm.c.security-code netpbm-10.58.01/converter/ppm/ppmtoxpm.c
1ab173
--- netpbm-10.58.01/converter/ppm/ppmtoxpm.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ppmtoxpm.c	2012-04-09 15:40:03.214619651 +0200
1ab173
@@ -197,6 +197,7 @@ genNumstr(unsigned int const input, int
1ab173
     unsigned int i;
1ab173
 
1ab173
     /* Allocate memory for printed number.  Abort if error. */
1ab173
+    overflow_add(digits, 1);
1ab173
     if (!(str = (char *) malloc(digits + 1)))
1ab173
         pm_error("out of memory");
1ab173
 
1ab173
@@ -314,6 +315,7 @@ genCmap(colorhist_vector const chv,
1ab173
     unsigned int charsPerPixel;
1ab173
     unsigned int xpmMaxval;
1ab173
     
1ab173
+    if (includeTransparent) overflow_add(ncolors, 1);
1ab173
     MALLOCARRAY(cmap, cmapSize);
1ab173
     if (cmapP == NULL)
1ab173
         pm_error("Out of memory allocating %u bytes for a color map.",
1ab173
diff -up netpbm-10.58.01/converter/ppm/qrttoppm.c.security-code netpbm-10.58.01/converter/ppm/qrttoppm.c
1ab173
--- netpbm-10.58.01/converter/ppm/qrttoppm.c.security-code	2012-04-09 15:31:42.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/qrttoppm.c	2012-04-09 15:40:03.215619638 +0200
1ab173
@@ -46,7 +46,7 @@ main( argc, argv )
1ab173
 
1ab173
     ppm_writeppminit( stdout, cols, rows, maxval, 0 );
1ab173
     pixelrow = ppm_allocrow( cols );
1ab173
-    buf = (unsigned char *) malloc( 3 * cols );
1ab173
+    buf = (unsigned char *) malloc2( 3 , cols );
1ab173
     if ( buf == (unsigned char *) 0 )
1ab173
 	pm_error( "out of memory" );
1ab173
 
1ab173
diff -up netpbm-10.58.01/converter/ppm/sldtoppm.c.security-code netpbm-10.58.01/converter/ppm/sldtoppm.c
1ab173
--- netpbm-10.58.01/converter/ppm/sldtoppm.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/sldtoppm.c	2012-04-09 15:40:03.216619626 +0200
1ab173
@@ -455,6 +455,8 @@ slider(slvecfn   slvec,
1ab173
     
1ab173
     /* Allocate image buffer and clear it to black. */
1ab173
     
1ab173
+    overflow_add(ixdots,1);
1ab173
+    overflow_add(iydots,1);
1ab173
     pixels = ppm_allocarray(pixcols = ixdots + 1, pixrows = iydots + 1);
1ab173
     PPM_ASSIGN(rgbcolor, 0, 0, 0);
1ab173
     ppmd_filledrectangle(pixels, pixcols, pixrows, pixmaxval, 0, 0,
1ab173
diff -up netpbm-10.58.01/converter/ppm/ximtoppm.c.security-code netpbm-10.58.01/converter/ppm/ximtoppm.c
1ab173
--- netpbm-10.58.01/converter/ppm/ximtoppm.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/ximtoppm.c	2012-04-09 15:40:03.216619626 +0200
1ab173
@@ -117,6 +117,7 @@ ReadXimHeader(FILE *     const in_fp,
1ab173
     header->bits_channel = atoi(a_head.bits_per_channel);
1ab173
     header->alpha_flag = atoi(a_head.alpha_channel);
1ab173
     if (strlen(a_head.author)) {
1ab173
+    	overflow_add(strlen(a_head.author),1);
1ab173
         if (!(header->author = calloc((unsigned int)strlen(a_head.author)+1,
1ab173
                 1))) {
1ab173
             pm_message("ReadXimHeader: can't calloc author string" );
1ab173
@@ -126,6 +127,7 @@ ReadXimHeader(FILE *     const in_fp,
1ab173
         strncpy(header->author, a_head.author, strlen(a_head.author));
1ab173
     }
1ab173
     if (strlen(a_head.date)) {
1ab173
+        overflow_add(strlen(a_head.date),1);
1ab173
         if (!(header->date =calloc((unsigned int)strlen(a_head.date)+1,1))){
1ab173
             pm_message("ReadXimHeader: can't calloc date string" );
1ab173
             return(0);
1ab173
@@ -134,6 +136,7 @@ ReadXimHeader(FILE *     const in_fp,
1ab173
         strncpy(header->date, a_head.date, strlen(a_head.date));
1ab173
     }
1ab173
     if (strlen(a_head.program)) {
1ab173
+        overflow_add(strlen(a_head.program),1);
1ab173
         if (!(header->program = calloc(
1ab173
                     (unsigned int)strlen(a_head.program) + 1, 1))) {
1ab173
             pm_message("ReadXimHeader: can't calloc program string" );
1ab173
@@ -160,6 +163,7 @@ ReadXimHeader(FILE *     const in_fp,
1ab173
     if (header->nchannels == 3 && header->bits_channel == 8)
1ab173
         header->ncolors = 0;
1ab173
     else if (header->nchannels == 1 && header->bits_channel == 8) {
1ab173
+	overflow2(header->ncolors, sizeof(Color));
1ab173
         header->colors = (Color *)calloc((unsigned int)header->ncolors,
1ab173
                 sizeof(Color));
1ab173
         if (header->colors == NULL) {
1ab173
diff -up netpbm-10.58.01/converter/ppm/yuvtoppm.c.security-code netpbm-10.58.01/converter/ppm/yuvtoppm.c
1ab173
--- netpbm-10.58.01/converter/ppm/yuvtoppm.c.security-code	2012-04-09 15:31:44.000000000 +0200
1ab173
+++ netpbm-10.58.01/converter/ppm/yuvtoppm.c	2012-04-09 15:40:03.218619602 +0200
1ab173
@@ -72,6 +72,7 @@ main(argc, argv)
1ab173
 
1ab173
 	ppm_writeppminit(stdout, cols, rows, (pixval) 255, 0);
1ab173
 	pixrow = ppm_allocrow(cols);
1ab173
+    overflow_add(cols, 1);
1ab173
     MALLOCARRAY(yuvbuf, (cols+1)/2);
1ab173
     if (yuvbuf == NULL)
1ab173
         pm_error("Unable to allocate YUV buffer for %d columns.", cols);
1ab173
diff -up netpbm-10.58.01/editor/pamcut.c.security-code netpbm-10.58.01/editor/pamcut.c
1ab173
--- netpbm-10.58.01/editor/pamcut.c.security-code	2012-04-09 15:31:33.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/pamcut.c	2012-04-09 15:40:03.218619602 +0200
1ab173
@@ -655,6 +655,8 @@ cutOneImage(FILE *             const ifP
1ab173
 
1ab173
     outpam = inpam;    /* Initial value -- most fields should be same */
1ab173
     outpam.file   = ofP;
1ab173
+    overflow_add(rightcol, 1);
1ab173
+    overflow_add(bottomrow, 1);
1ab173
     outpam.width  = rightcol - leftcol + 1;
1ab173
     outpam.height = bottomrow - toprow + 1;
1ab173
 
1ab173
diff -up netpbm-10.58.01/editor/pbmreduce.c.security-code netpbm-10.58.01/editor/pbmreduce.c
1ab173
--- netpbm-10.58.01/editor/pbmreduce.c.security-code	2012-04-09 15:31:33.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/pbmreduce.c	2012-04-09 15:40:03.219619590 +0200
1ab173
@@ -94,6 +94,7 @@ main( argc, argv )
1ab173
     if (halftone == QT_FS) {
1ab173
         unsigned int col;
1ab173
         /* Initialize Floyd-Steinberg. */
1ab173
+        overflow_add(newcols, 2);
1ab173
         MALLOCARRAY(thiserr, newcols + 2);
1ab173
         MALLOCARRAY(nexterr, newcols + 2);
1ab173
         if (thiserr == NULL || nexterr == NULL)
1ab173
diff -up netpbm-10.58.01/editor/pnmgamma.c.security-code netpbm-10.58.01/editor/pnmgamma.c
1ab173
--- netpbm-10.58.01/editor/pnmgamma.c.security-code	2012-04-09 15:31:34.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/pnmgamma.c	2012-04-09 15:40:03.220619577 +0200
1ab173
@@ -586,6 +586,7 @@ createGammaTables(enum transferFunction
1ab173
                   xelval **             const btableP) {
1ab173
 
1ab173
     /* Allocate space for the tables. */
1ab173
+    overflow_add(maxval, 1);
1ab173
     MALLOCARRAY(*rtableP, maxval+1);
1ab173
     MALLOCARRAY(*gtableP, maxval+1);
1ab173
     MALLOCARRAY(*btableP, maxval+1);
1ab173
diff -up netpbm-10.58.01/editor/pnmhisteq.c.security-code netpbm-10.58.01/editor/pnmhisteq.c
1ab173
--- netpbm-10.58.01/editor/pnmhisteq.c.security-code	2012-04-09 15:31:33.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/pnmhisteq.c	2012-04-09 15:40:03.220619577 +0200
1ab173
@@ -103,6 +103,7 @@ computeLuminosityHistogram(xel * const *
1ab173
     unsigned int pixelCount;
1ab173
     unsigned int * lumahist;
1ab173
 
1ab173
+    overflow_add(maxval, 1);
1ab173
     MALLOCARRAY(lumahist, maxval + 1);
1ab173
     if (lumahist == NULL)
1ab173
         pm_error("Out of storage allocating array for %u histogram elements",
1ab173
diff -up netpbm-10.58.01/editor/pnmindex.csh.security-code netpbm-10.58.01/editor/pnmindex.csh
1ab173
--- netpbm-10.58.01/editor/pnmindex.csh.security-code	2012-04-09 15:31:33.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/pnmindex.csh	2012-04-09 15:40:03.221619564 +0200
1ab173
@@ -1,5 +1,8 @@
1ab173
 #!/bin/csh -f
1ab173
 #
1ab173
+echo "Unsafe code, needs debugging, do not ship"
1ab173
+exit 1
1ab173
+#
1ab173
 # pnmindex - build a visual index of a bunch of anymaps
1ab173
 #
1ab173
 # Copyright (C) 1991 by Jef Poskanzer.
1ab173
diff -up netpbm-10.58.01/editor/pnmpad.c.security-code netpbm-10.58.01/editor/pnmpad.c
1ab173
--- netpbm-10.58.01/editor/pnmpad.c.security-code	2012-04-09 15:31:34.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/pnmpad.c	2012-04-09 15:40:03.221619564 +0200
1ab173
@@ -527,6 +527,8 @@ main(int argc, const char ** argv) {
1ab173
 
1ab173
     computePadSizes(cmdline, cols, rows, &lpad, &rpad, &tpad, &bpad);
1ab173
 
1ab173
+    overflow_add(cols, lpad);
1ab173
+    overflow_add(cols + lpad, rpad);
1ab173
     newcols = cols + lpad + rpad;
1ab173
 
1ab173
     if (PNM_FORMAT_TYPE(format) == PBM_TYPE)
1ab173
diff -up netpbm-10.58.01/editor/pnmremap.c.security-code netpbm-10.58.01/editor/pnmremap.c
1ab173
--- netpbm-10.58.01/editor/pnmremap.c.security-code	2012-04-09 15:31:33.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/pnmremap.c	2012-04-09 15:40:03.222619551 +0200
1ab173
@@ -409,7 +409,7 @@ initFserr(struct pam *   const pamP,
1ab173
     unsigned int plane;
1ab173
 
1ab173
     unsigned int const fserrSize = pamP->width + 2;
1ab173
-
1ab173
+    overflow_add(pamP->width, 2);
1ab173
     fserrP->width = pamP->width;
1ab173
 
1ab173
     MALLOCARRAY(fserrP->thiserr, pamP->depth);
1ab173
@@ -445,6 +445,7 @@ floydInitRow(struct pam * const pamP, st
1ab173
 
1ab173
     int col;
1ab173
     
1ab173
+    overflow_add(pamP->width, 2);
1ab173
     for (col = 0; col < pamP->width + 2; ++col) {
1ab173
         unsigned int plane;
1ab173
         for (plane = 0; plane < pamP->depth; ++plane) 
1ab173
diff -up netpbm-10.58.01/editor/pnmscalefixed.c.security-code netpbm-10.58.01/editor/pnmscalefixed.c
1ab173
--- netpbm-10.58.01/editor/pnmscalefixed.c.security-code	2012-04-09 15:31:34.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/pnmscalefixed.c	2012-04-09 15:40:03.223619538 +0200
1ab173
@@ -214,6 +214,8 @@ compute_output_dimensions(const struct c
1ab173
                           const int rows, const int cols,
1ab173
                           int * newrowsP, int * newcolsP) {
1ab173
 
1ab173
+    overflow2(rows, cols);
1ab173
+
1ab173
     if (cmdline.pixels) {
1ab173
         if (rows * cols <= cmdline.pixels) {
1ab173
             *newrowsP = rows;
1ab173
@@ -265,6 +267,8 @@ compute_output_dimensions(const struct c
1ab173
 
1ab173
     if (*newcolsP < 1) *newcolsP = 1;
1ab173
     if (*newrowsP < 1) *newrowsP = 1;
1ab173
+    
1ab173
+    overflow2(*newcolsP, *newrowsP);
1ab173
 }        
1ab173
 
1ab173
 
1ab173
@@ -446,6 +450,9 @@ main(int argc, char **argv ) {
1ab173
        unfilled.  We can address that by stretching, whereas the other
1ab173
        case would require throwing away some of the input.
1ab173
     */
1ab173
+    
1ab173
+    overflow2(newcols, SCALE);
1ab173
+    overflow2(newrows, SCALE);
1ab173
     sxscale = SCALE * newcols / cols;
1ab173
     syscale = SCALE * newrows / rows;
1ab173
 
1ab173
diff -up netpbm-10.58.01/editor/pnmshear.c.security-code netpbm-10.58.01/editor/pnmshear.c
1ab173
--- netpbm-10.58.01/editor/pnmshear.c.security-code	2012-04-09 15:31:33.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/pnmshear.c	2012-04-09 15:40:03.224619526 +0200
1ab173
@@ -15,6 +15,7 @@
1ab173
 #include <assert.h>
1ab173
 #include <math.h>
1ab173
 #include <string.h>
1ab173
+#include <limits.h>
1ab173
 
1ab173
 #include "pm_c_util.h"
1ab173
 #include "ppm.h"
1ab173
@@ -236,6 +237,11 @@ main(int argc, char * argv[]) {
1ab173
 
1ab173
     shearfac = fabs(tan(cmdline.angle));
1ab173
 
1ab173
+    if(rows * shearfac >= INT_MAX-1)
1ab173
+      pm_error("image too large");
1ab173
+    
1ab173
+    overflow_add(rows * shearfac, cols+1);
1ab173
+
1ab173
     newcols = rows * shearfac + cols + 0.999999;
1ab173
 
1ab173
     pnm_writepnminit(stdout, newcols, rows, newmaxval, newformat, 0);
1ab173
diff -up netpbm-10.58.01/editor/ppmdither.c.security-code netpbm-10.58.01/editor/ppmdither.c
1ab173
--- netpbm-10.58.01/editor/ppmdither.c.security-code	2012-04-09 15:31:33.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/ppmdither.c	2012-04-09 15:40:03.224619526 +0200
1ab173
@@ -355,7 +355,11 @@ dithMatrix(unsigned int const dithPower)
1ab173
         unsigned int const dithMatSize = 
1ab173
             (dithDim * sizeof(*dithMat)) + /* pointers */
1ab173
             (dithDim * dithDim * sizeof(**dithMat)); /* data */
1ab173
-        
1ab173
+
1ab173
+        overflow2(dithDim, sizeof(*dithMat));
1ab173
+        overflow3(dithDim, dithDim, sizeof(**dithMat));
1ab173
+        overflow_add(dithDim * sizeof(*dithMat), dithDim * dithDim * sizeof(**dithMat));
1ab173
+
1ab173
         dithMat = malloc(dithMatSize);
1ab173
         
1ab173
         if (dithMat == NULL) 
1ab173
diff -up netpbm-10.58.01/editor/specialty/pamoil.c.security-code netpbm-10.58.01/editor/specialty/pamoil.c
1ab173
--- netpbm-10.58.01/editor/specialty/pamoil.c.security-code	2012-04-09 15:31:33.000000000 +0200
1ab173
+++ netpbm-10.58.01/editor/specialty/pamoil.c	2012-04-09 15:40:03.224619526 +0200
1ab173
@@ -112,6 +112,7 @@ main(int argc, char *argv[] ) {
1ab173
     tuples = pnm_readpam(ifp, &inpam, PAM_STRUCT_SIZE(tuple_type));
1ab173
     pm_close(ifp);
1ab173
 
1ab173
+    overflow_add(inpam.maxval, 1);
1ab173
     MALLOCARRAY(hist, inpam.maxval + 1);
1ab173
     if (hist == NULL)
1ab173
         pm_error("Unable to allocate memory for histogram.");
1ab173
diff -up netpbm-10.58.01/generator/pbmtext.c.security-code netpbm-10.58.01/generator/pbmtext.c
1ab173
--- netpbm-10.58.01/generator/pbmtext.c.security-code	2012-04-09 15:31:34.000000000 +0200
1ab173
+++ netpbm-10.58.01/generator/pbmtext.c	2012-04-09 15:40:03.225619514 +0200
1ab173
@@ -96,12 +96,14 @@ parseCommandLine(int argc, const char **
1ab173
         
1ab173
         for (i = 1; i < argc; ++i) {
1ab173
             if (i > 1) {
1ab173
+                overflow_add(totaltextsize, 1);
1ab173
                 totaltextsize += 1;
1ab173
                 text = realloc(text, totaltextsize);
1ab173
                 if (text == NULL)
1ab173
                     pm_error("out of memory allocating space for input text");
1ab173
                 strcat(text, " ");
1ab173
             } 
1ab173
+            overflow_add(totaltextsize, strlen(argv[i]));
1ab173
             totaltextsize += strlen(argv[i]);
1ab173
             text = realloc(text, totaltextsize);
1ab173
             if (text == NULL)
1ab173
@@ -712,6 +714,7 @@ getText(const char          cmdline_text
1ab173
                 pm_error("A line of input text is longer than %u characters."
1ab173
                          "Cannot process.", (unsigned)sizeof(buf)-1);
1ab173
             if (lineCount >= maxlines) {
1ab173
+		overflow2(maxlines, 2);
1ab173
                 maxlines *= 2;
1ab173
                 REALLOCARRAY(text_array, maxlines);
1ab173
                 if (text_array == NULL)
1ab173
@@ -832,6 +835,7 @@ main(int argc, const char *argv[]) {
1ab173
             hmargin = fontP->maxwidth;
1ab173
         } else {
1ab173
             vmargin = fontP->maxheight;
1ab173
+	    overflow2(2, fontP->maxwidth);
1ab173
             hmargin = 2 * fontP->maxwidth;
1ab173
         }
1ab173
     }
1ab173
diff -up netpbm-10.58.01/generator/pgmcrater.c.security-code netpbm-10.58.01/generator/pgmcrater.c
1ab173
--- netpbm-10.58.01/generator/pgmcrater.c.security-code	2012-04-09 15:31:34.000000000 +0200
1ab173
+++ netpbm-10.58.01/generator/pgmcrater.c	2012-04-09 15:40:03.226619502 +0200
1ab173
@@ -130,7 +130,7 @@ static void gencraters()
1ab173
     /* Acquire the elevation array and initialize it to mean
1ab173
        surface elevation. */
1ab173
 
1ab173
-    MALLOCARRAY(aux, SCRX * SCRY);
1ab173
+    aux = (unsigned short *) malloc3(SCRX, SCRY, sizeof(short));
1ab173
     if (aux == NULL) 
1ab173
         pm_error("out of memory allocating elevation array");
1ab173
 
1ab173
diff -up netpbm-10.58.01/generator/pgmkernel.c.security-code netpbm-10.58.01/generator/pgmkernel.c
1ab173
--- netpbm-10.58.01/generator/pgmkernel.c.security-code	2012-04-09 15:31:34.000000000 +0200
1ab173
+++ netpbm-10.58.01/generator/pgmkernel.c	2012-04-09 15:40:03.226619502 +0200
1ab173
@@ -68,7 +68,7 @@ main ( argc, argv )
1ab173
     kycenter = (fysize - 1) / 2.0;
1ab173
     ixsize = fxsize + 0.999;
1ab173
     iysize = fysize + 0.999;
1ab173
-    MALLOCARRAY(fkernel, ixsize * iysize);
1ab173
+    fkernel = (double *) malloc3 (ixsize, iysize, sizeof(double));
1ab173
     for (i = 0; i < iysize; i++) 
1ab173
         for (j = 0; j < ixsize; j++) {
1ab173
             fkernel[i*ixsize+j] = 1.0 / (1.0 + w * sqrt((double)
1ab173
diff -up netpbm-10.58.01/lib/libpam.c.security-code netpbm-10.58.01/lib/libpam.c
1ab173
--- netpbm-10.58.01/lib/libpam.c.security-code	2012-04-09 15:31:38.000000000 +0200
1ab173
+++ netpbm-10.58.01/lib/libpam.c	2012-04-09 15:40:03.227619490 +0200
1ab173
@@ -220,7 +220,8 @@ allocPamRow(const struct pam * const pam
1ab173
     unsigned int const bytesPerTuple = allocationDepth(pamP) * sizeof(sample);
1ab173
     tuple * tuplerow;
1ab173
 
1ab173
-    tuplerow = malloc(pamP->width * (sizeof(tuple *) + bytesPerTuple));
1ab173
+    overflow_add(sizeof(tuple *), bytesPerTuple);
1ab173
+    tuplerow = malloc2(pamP->width, (sizeof(tuple *) + bytesPerTuple));
1ab173
                       
1ab173
     if (tuplerow != NULL) {
1ab173
         /* Now we initialize the pointers to the individual tuples
1ab173
diff -up netpbm-10.58.01/lib/libpammap.c.security-code netpbm-10.58.01/lib/libpammap.c
1ab173
--- netpbm-10.58.01/lib/libpammap.c.security-code	2012-04-09 15:31:38.000000000 +0200
1ab173
+++ netpbm-10.58.01/lib/libpammap.c	2012-04-09 15:40:03.228619477 +0200
1ab173
@@ -104,6 +104,8 @@ allocTupleIntListItem(struct pam * const
1ab173
     */
1ab173
     struct tupleint_list_item * retval;
1ab173
 
1ab173
+    overflow2(pamP->depth, sizeof(sample));
1ab173
+    overflow_add(sizeof(*retval)-sizeof(retval->tupleint.tuple), pamP->depth*sizeof(sample));
1ab173
     unsigned int const size = 
1ab173
         sizeof(*retval) - sizeof(retval->tupleint.tuple) 
1ab173
         + pamP->depth * sizeof(sample);
1ab173
diff -up netpbm-10.58.01/lib/libpbm1.c.security-code netpbm-10.58.01/lib/libpbm1.c
1ab173
--- netpbm-10.58.01/lib/libpbm1.c.security-code	2012-04-09 15:31:38.000000000 +0200
1ab173
+++ netpbm-10.58.01/lib/libpbm1.c	2012-04-09 15:40:03.228619477 +0200
1ab173
@@ -77,6 +77,7 @@ pbm_check(FILE * file, const enum pm_che
1ab173
         pm_message("pm_filepos passed to pm_check() is %u bytes",
1ab173
                    sizeof(pm_filepos));
1ab173
 #endif
1ab173
+        overflow2(bytes_per_row, rows);
1ab173
         pm_check(file, check_type, need_raster_size, retval_p);
1ab173
     }
1ab173
 }
1ab173
diff -up netpbm-10.58.01/lib/libpm.c.security-code netpbm-10.58.01/lib/libpm.c
1ab173
--- netpbm-10.58.01/lib/libpm.c.security-code	2012-04-09 15:31:38.000000000 +0200
1ab173
+++ netpbm-10.58.01/lib/libpm.c	2012-04-09 15:40:03.229619464 +0200
1ab173
@@ -808,4 +808,53 @@ pm_parse_height(const char * const arg)
1ab173
 }
1ab173
 
1ab173
 
1ab173
+/*
1ab173
+ *	Maths wrapping
1ab173
+ */
1ab173
+ 
1ab173
+void __overflow2(int a, int b)
1ab173
+{
1ab173
+	if(a < 0 || b < 0)
1ab173
+		pm_error("object too large");
1ab173
+	if(b == 0)
1ab173
+		return;
1ab173
+	if(a > INT_MAX / b)
1ab173
+		pm_error("object too large");
1ab173
+}
1ab173
+
1ab173
+void overflow3(int a, int b, int c)
1ab173
+{
1ab173
+	overflow2(a,b);
1ab173
+	overflow2(a*b, c);
1ab173
+}
1ab173
+
1ab173
+void overflow_add(int a, int b)
1ab173
+{
1ab173
+	if( a > INT_MAX - b)
1ab173
+		pm_error("object too large");
1ab173
+}
1ab173
+
1ab173
+void *malloc2(int a, int b)
1ab173
+{
1ab173
+	overflow2(a, b);
1ab173
+	if(a*b == 0)
1ab173
+		pm_error("Zero byte allocation");
1ab173
+	return malloc(a*b);
1ab173
+}
1ab173
+
1ab173
+void *malloc3(int a, int b, int c)
1ab173
+{
1ab173
+	overflow3(a, b, c);
1ab173
+	if(a*b*c == 0)
1ab173
+		pm_error("Zero byte allocation");
1ab173
+	return malloc(a*b*c);
1ab173
+}
1ab173
+
1ab173
+void *realloc2(void * a, int b, int c)
1ab173
+{
1ab173
+	overflow2(b, c);
1ab173
+	if(b*c == 0)
1ab173
+		pm_error("Zero byte allocation");
1ab173
+	return realloc(a, b*c);
1ab173
+}
1ab173
 
1ab173
diff -up netpbm-10.58.01/lib/pm.h.security-code netpbm-10.58.01/lib/pm.h
1ab173
--- netpbm-10.58.01/lib/pm.h.security-code	2012-04-09 15:31:38.000000000 +0200
1ab173
+++ netpbm-10.58.01/lib/pm.h	2012-04-09 15:40:03.229619464 +0200
1ab173
@@ -432,4 +432,11 @@ pm_parse_height(const char * const arg);
1ab173
 #endif
1ab173
 
1ab173
 
1ab173
+void *malloc2(int, int);
1ab173
+void *malloc3(int, int, int);
1ab173
+#define overflow2(a,b) __overflow2(a,b)
1ab173
+void __overflow2(int, int);
1ab173
+void overflow3(int, int, int);
1ab173
+void overflow_add(int, int);
1ab173
+
1ab173
 #endif
1ab173
diff -up netpbm-10.58.01/other/pnmcolormap.c.security-code netpbm-10.58.01/other/pnmcolormap.c
1ab173
--- netpbm-10.58.01/other/pnmcolormap.c.security-code	2012-04-09 15:31:32.000000000 +0200
1ab173
+++ netpbm-10.58.01/other/pnmcolormap.c	2012-04-09 15:40:03.230619451 +0200
1ab173
@@ -840,6 +840,7 @@ colormapToSquare(struct pam * const pamP
1ab173
             pamP->width = intsqrt;
1ab173
         else 
1ab173
             pamP->width = intsqrt + 1;
1ab173
+            overflow_add(intsqrt, 1);
1ab173
     }
1ab173
     {
1ab173
         unsigned int const intQuotient = colormap.size / pamP->width;
1ab173
diff -up netpbm-10.58.01/urt/README.security-code netpbm-10.58.01/urt/README
1ab173
--- netpbm-10.58.01/urt/README.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/urt/README	2012-04-09 15:40:03.231619438 +0200
1ab173
@@ -18,3 +18,8 @@ in its initializer in the original.  But
1ab173
 defines stdout as a variable, so that wouldn't compile.  So I changed
1ab173
 it to NULL and added a line to rle_hdr_init to set that field to
1ab173
 'stdout' dynamically.  2000.06.02 BJH.
1ab173
+
1ab173
+Redid the code to check for maths overflows and other crawly horrors.
1ab173
+Removed pipe through and compress support (unsafe)
1ab173
+
1ab173
+Alan Cox <alan@redhat.com>
1ab173
diff -up netpbm-10.58.01/urt/rle_addhist.c.security-code netpbm-10.58.01/urt/rle_addhist.c
1ab173
--- netpbm-10.58.01/urt/rle_addhist.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/urt/rle_addhist.c	2012-04-09 15:40:03.231619438 +0200
1ab173
@@ -14,6 +14,8 @@
1ab173
  * If you modify this software, you should include a notice giving the
1ab173
  * name of the person performing the modification, the date of modification,
1ab173
  * and the reason for such modification.
1ab173
+ *
1ab173
+ *  2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
1ab173
  */
1ab173
 /* 
1ab173
  * rle_addhist.c - Add to the HISTORY comment in header
1ab173
@@ -71,13 +73,19 @@ rle_addhist(char *          argv[],
1ab173
         return;
1ab173
     
1ab173
     length = 0;
1ab173
-    for (i = 0; argv[i]; ++i)
1ab173
+    for (i = 0; argv[i]; ++i) {
1ab173
+	overflow_add(length, strlen(argv[i]));
1ab173
+	overflow_add(length+1, strlen(argv[i]));
1ab173
         length += strlen(argv[i]) +1;   /* length of each arg plus space. */
1ab173
+    }
1ab173
 
1ab173
     time(&temp);
1ab173
     timedate = ctime(&temp);
1ab173
     length += strlen(timedate);        /* length of date and time in ASCII. */
1ab173
 
1ab173
+    overflow_add(strlen(padding), 4);
1ab173
+    overflow_add(strlen(histoire), strlen(padding) + 4);
1ab173
+    overflow_add(length, strlen(histoire) + strlen(padding) + 4);
1ab173
     length += strlen(padding) + 3 + strlen(histoire) + 1;
1ab173
         /* length of padding, "on "  and length of history name plus "="*/
1ab173
     if (in_hdr) /* if we are interested in the old comments... */
1ab173
@@ -85,9 +93,12 @@ rle_addhist(char *          argv[],
1ab173
     else
1ab173
         old = NULL;
1ab173
     
1ab173
-    if (old && *old)
1ab173
+    if (old && *old) {
1ab173
+	overflow_add(length, strlen(old));
1ab173
         length += strlen(old);       /* add length if there. */
1ab173
+    }
1ab173
 
1ab173
+    overflow_add(length, 1);
1ab173
     ++length;                               /*Cater for the null. */
1ab173
 
1ab173
     MALLOCARRAY(newc, length);
1ab173
diff -up netpbm-10.58.01/urt/rle_getrow.c.security-code netpbm-10.58.01/urt/rle_getrow.c
1ab173
--- netpbm-10.58.01/urt/rle_getrow.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/urt/rle_getrow.c	2012-04-09 15:40:03.232619426 +0200
1ab173
@@ -17,6 +17,8 @@
1ab173
  *
1ab173
  *  Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
1ab173
  *  to have all "void" functions so declared.
1ab173
+ *
1ab173
+ *  2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
1ab173
  */
1ab173
 /* 
1ab173
  * rle_getrow.c - Read an RLE file in.
1ab173
@@ -168,6 +170,7 @@ rle_get_setup(rle_hdr * const the_hdr) {
1ab173
         register char * cp;
1ab173
 
1ab173
         VAXSHORT( comlen, infile ); /* get comment length */
1ab173
+	overflow_add(comlen, 1);
1ab173
         evenlen = (comlen + 1) & ~1;    /* make it even */
1ab173
         if ( evenlen )
1ab173
         {
1ab173
diff -up netpbm-10.58.01/urt/rle_hdr.c.security-code netpbm-10.58.01/urt/rle_hdr.c
1ab173
--- netpbm-10.58.01/urt/rle_hdr.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/urt/rle_hdr.c	2012-04-09 15:40:03.233619414 +0200
1ab173
@@ -14,6 +14,8 @@
1ab173
  * If you modify this software, you should include a notice giving the
1ab173
  * name of the person performing the modification, the date of modification,
1ab173
  * and the reason for such modification.
1ab173
+ *
1ab173
+ *  2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
1ab173
  */
1ab173
 /* 
1ab173
  * rle_hdr.c - Functions to manipulate rle_hdr structures.
1ab173
@@ -80,7 +82,10 @@ int img_num;
1ab173
     /* Fill in with copies of the strings. */
1ab173
     if ( the_hdr->cmd != pgmname )
1ab173
     {
1ab173
-	char *tmp = (char *)malloc( strlen( pgmname ) + 1 );
1ab173
+	char *tmp ;
1ab173
+
1ab173
+	overflow_add(strlen(pgmname), 1);
1ab173
+	tmp = malloc( strlen( pgmname ) + 1 );
1ab173
 	RLE_CHECK_ALLOC( pgmname, tmp, 0 );
1ab173
 	strcpy( tmp, pgmname );
1ab173
 	the_hdr->cmd = tmp;
1ab173
@@ -88,7 +93,9 @@ int img_num;
1ab173
 
1ab173
     if ( the_hdr->file_name != fname )
1ab173
     {
1ab173
-	char *tmp = (char *)malloc( strlen( fname ) + 1 );
1ab173
+	char *tmp;
1ab173
+	overflow_add(strlen(fname), 1);
1ab173
+	tmp = malloc( strlen( fname ) + 1 );
1ab173
 	RLE_CHECK_ALLOC( pgmname, tmp, 0 );
1ab173
 	strcpy( tmp, fname );
1ab173
 	the_hdr->file_name = tmp;
1ab173
@@ -153,6 +160,7 @@ rle_hdr *from_hdr, *to_hdr;
1ab173
     if ( to_hdr->bg_color )
1ab173
     {
1ab173
 	int size = to_hdr->ncolors * sizeof(int);
1ab173
+	overflow2(to_hdr->ncolors, sizeof(int));
1ab173
 	to_hdr->bg_color = (int *)malloc( size );
1ab173
 	RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->bg_color, "background color" );
1ab173
 	memcpy( to_hdr->bg_color, from_hdr->bg_color, size );
1ab173
@@ -161,7 +169,7 @@ rle_hdr *from_hdr, *to_hdr;
1ab173
     if ( to_hdr->cmap )
1ab173
     {
1ab173
 	int size = to_hdr->ncmap * (1 << to_hdr->cmaplen) * sizeof(rle_map);
1ab173
-	to_hdr->cmap = (rle_map *)malloc( size );
1ab173
+	to_hdr->cmap = (rle_map *)malloc3( to_hdr->ncmap, 1<<to_hdr->cmaplen, sizeof(rle_map));
1ab173
 	RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->cmap, "color map" );
1ab173
 	memcpy( to_hdr->cmap, from_hdr->cmap, size );
1ab173
     }
1ab173
@@ -174,11 +182,16 @@ rle_hdr *from_hdr, *to_hdr;
1ab173
 	int size = 0;
1ab173
 	CONST_DECL char **cp;
1ab173
 	for ( cp=to_hdr->comments; *cp; cp++ )
1ab173
+	{
1ab173
+	    overflow_add(size, 1);
1ab173
 	    size++;		/* Count the comments. */
1ab173
+ 	}
1ab173
 	/* Check if there are really any comments. */
1ab173
 	if ( size )
1ab173
 	{
1ab173
+	    overflow_add(size, 1);
1ab173
 	    size++;		/* Copy the NULL pointer, too. */
1ab173
+	    overflow2(size, sizeof(char *));
1ab173
 	    size *= sizeof(char *);
1ab173
 	    to_hdr->comments = (CONST_DECL char **)malloc( size );
1ab173
 	    RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->comments, "comments" );
1ab173
diff -up netpbm-10.58.01/urt/rle.h.security-code netpbm-10.58.01/urt/rle.h
1ab173
--- netpbm-10.58.01/urt/rle.h.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/urt/rle.h	2012-04-09 15:40:03.233619414 +0200
1ab173
@@ -14,6 +14,9 @@
1ab173
  * If you modify this software, you should include a notice giving the
1ab173
  * name of the person performing the modification, the date of modification,
1ab173
  * and the reason for such modification.
1ab173
+ *
1ab173
+ *  2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
1ab173
+ *  Header declarations needed
1ab173
  */
1ab173
 /* 
1ab173
  * rle.h - Global declarations for Utah Raster Toolkit RLE programs.
1ab173
@@ -160,6 +163,17 @@ rle_hdr             /* End of typedef. *
1ab173
  */
1ab173
 extern rle_hdr rle_dflt_hdr;
1ab173
 
1ab173
+/* 
1ab173
+ * Provided by pm library
1ab173
+ */
1ab173
+ 
1ab173
+extern void overflow_add(int, int);
1ab173
+#define overflow2(a,b) __overflow2(a,b)
1ab173
+extern void __overflow2(int, int);
1ab173
+extern void overflow3(int, int, int);
1ab173
+extern void *malloc2(int, int);
1ab173
+extern void *malloc3(int, int, int);
1ab173
+extern void *realloc2(void *, int, int);
1ab173
 
1ab173
 /* Declare RLE library routines. */
1ab173
 
1ab173
diff -up netpbm-10.58.01/urt/rle_open_f.c.security-code netpbm-10.58.01/urt/rle_open_f.c
1ab173
--- netpbm-10.58.01/urt/rle_open_f.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/urt/rle_open_f.c	2012-04-09 15:40:03.234619402 +0200
1ab173
@@ -163,65 +163,7 @@ dealWithSubprocess(const char *  const f
1ab173
                    FILE **       const fpP,
1ab173
                    bool *        const noSubprocessP,
1ab173
                    const char ** const errorP) {
1ab173
-
1ab173
-#ifdef NO_OPEN_PIPES
1ab173
     *noSubprocessP = TRUE;
1ab173
-#else
1ab173
-    const char *cp;
1ab173
-
1ab173
-    reapChildren(catchingChildrenP, pids);
1ab173
-
1ab173
-    /*  Real file, not stdin or stdout.  If name ends in ".Z",
1ab173
-     *  pipe from/to un/compress (depending on r/w mode).
1ab173
-     *  
1ab173
-     *  If it starts with "|", popen that command.
1ab173
-     */
1ab173
-        
1ab173
-    cp = file_name + strlen(file_name) - 2;
1ab173
-    /* Pipe case. */
1ab173
-    if (file_name[0] == '|') {
1ab173
-        pid_t thepid;     /* PID from my_popen */
1ab173
-
1ab173
-        *noSubprocessP = FALSE;
1ab173
-
1ab173
-        *fpP = my_popen(file_name + 1, mode, &thepid);
1ab173
-        if (*fpP == NULL)
1ab173
-            *errorP = "%s: can't invoke <<%s>> for %s: ";
1ab173
-        else {
1ab173
-            /* One more child to catch, eventually. */
1ab173
-            if (*catchingChildrenP < MAX_CHILDREN)
1ab173
-                pids[(*catchingChildrenP)++] = thepid;
1ab173
-        }
1ab173
-    } else if (cp > file_name && *cp == '.' && *(cp + 1) == 'Z' ) {
1ab173
-        /* Compress case. */
1ab173
-        pid_t thepid;     /* PID from my_popen. */
1ab173
-        const char * command;
1ab173
-
1ab173
-        *noSubprocessP = FALSE;
1ab173
-        
1ab173
-        if (*mode == 'w')
1ab173
-            pm_asprintf(&command, "compress > %s", file_name);
1ab173
-        else if (*mode == 'a')
1ab173
-            pm_asprintf(&command, "compress >> %s", file_name);
1ab173
-        else
1ab173
-            pm_asprintf(&command, "compress -d < %s", file_name);
1ab173
-        
1ab173
-        *fpP = my_popen(command, mode, &thepid);
1ab173
-
1ab173
-        if (*fpP == NULL)
1ab173
-            *errorP = "%s: can't invoke 'compress' program, "
1ab173
-                "trying to open %s for %s";
1ab173
-        else {
1ab173
-            /* One more child to catch, eventually. */
1ab173
-            if (*catchingChildrenP < MAX_CHILDREN)
1ab173
-                pids[(*catchingChildrenP)++] = thepid;
1ab173
-        }
1ab173
-        pm_strfree(command);
1ab173
-    } else {
1ab173
-        *noSubprocessP = TRUE;
1ab173
-        *errorP = NULL;
1ab173
-    }
1ab173
-#endif
1ab173
 }
1ab173
 
1ab173
 
1ab173
diff -up netpbm-10.58.01/urt/rle_putcom.c.security-code netpbm-10.58.01/urt/rle_putcom.c
1ab173
--- netpbm-10.58.01/urt/rle_putcom.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/urt/rle_putcom.c	2012-04-09 15:40:03.234619402 +0200
1ab173
@@ -14,6 +14,8 @@
1ab173
  * If you modify this software, you should include a notice giving the
1ab173
  * name of the person performing the modification, the date of modification,
1ab173
  * and the reason for such modification.
1ab173
+ *
1ab173
+ *  2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
1ab173
  */
1ab173
 /* 
1ab173
  * rle_putcom.c - Add a picture comment to the header struct.
1ab173
@@ -98,12 +100,14 @@ rle_putcom(const char * const value,
1ab173
         const char * v;
1ab173
         const char ** old_comments;
1ab173
         int i;
1ab173
-        for (i = 2, cp = the_hdr->comments; *cp != NULL; ++i, ++cp)
1ab173
+        for (i = 2, cp = the_hdr->comments; *cp != NULL; ++i, ++cp) {
1ab173
+	    overflow_add(i, 1);
1ab173
             if (match(value, *cp) != NULL) {
1ab173
                 v = *cp;
1ab173
                 *cp = value;
1ab173
                 return v;
1ab173
             }
1ab173
+	}
1ab173
         /* Not found */
1ab173
         /* Can't realloc because somebody else might be pointing to this
1ab173
          * comments block.  Of course, if this were true, then the
1ab173
diff -up netpbm-10.58.01/urt/Runput.c.security-code netpbm-10.58.01/urt/Runput.c
1ab173
--- netpbm-10.58.01/urt/Runput.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/urt/Runput.c	2012-04-09 15:40:03.235619390 +0200
1ab173
@@ -17,6 +17,8 @@
1ab173
  *
1ab173
  *  Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
1ab173
  *  to have all "void" functions so declared.
1ab173
+ *
1ab173
+ *  2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
1ab173
  */
1ab173
 /* 
1ab173
  * Runput.c - General purpose Run Length Encoding.
1ab173
@@ -202,9 +204,11 @@ RunSetup(rle_hdr * the_hdr)
1ab173
     if ( the_hdr->background != 0 )
1ab173
     {
1ab173
 	register int i;
1ab173
-	register rle_pixel *background =
1ab173
-	    (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) );
1ab173
+	register rle_pixel *background;
1ab173
 	register int *bg_color;
1ab173
+
1ab173
+	overflow_add(the_hdr->ncolors,1);
1ab173
+	background = (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) );
1ab173
 	/* 
1ab173
 	 * If even number of bg color bytes, put out one more to get to 
1ab173
 	 * 16 bit boundary.
1ab173
@@ -224,7 +228,7 @@ RunSetup(rle_hdr * the_hdr)
1ab173
 	/* Big-endian machines are harder */
1ab173
 	register int i, nmap = (1 << the_hdr->cmaplen) *
1ab173
 			       the_hdr->ncmap;
1ab173
-	register char *h_cmap = (char *)malloc( nmap * 2 );
1ab173
+	register char *h_cmap = (char *)malloc2( nmap, 2 );
1ab173
 	if ( h_cmap == NULL )
1ab173
 	{
1ab173
 	    fprintf( stderr,
1ab173
diff -up netpbm-10.58.01/urt/scanargs.c.security-code netpbm-10.58.01/urt/scanargs.c
1ab173
--- netpbm-10.58.01/urt/scanargs.c.security-code	2012-04-09 15:31:45.000000000 +0200
1ab173
+++ netpbm-10.58.01/urt/scanargs.c	2012-04-09 15:40:03.235619390 +0200
1ab173
@@ -38,6 +38,8 @@
1ab173
  *
1ab173
  *  Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
1ab173
  *  to have all "void" functions so declared.
1ab173
+ *
1ab173
+ *  2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
1ab173
  */
1ab173
 
1ab173
 #include <stdio.h>
1ab173
@@ -63,8 +65,8 @@ typedef int *ptr;
1ab173
 /* 
1ab173
  * Storage allocation macros
1ab173
  */
1ab173
-#define NEW( type, cnt )	(type *) malloc( (cnt) * sizeof( type ) )
1ab173
-#define RENEW( type, ptr, cnt )	(type *) realloc( ptr, (cnt) * sizeof( type ) )
1ab173
+#define NEW( type, cnt )	(type *) malloc2( (cnt) , sizeof( type ) )
1ab173
+#define RENEW( type, ptr, cnt )	(type *) realloc2( ptr, (cnt), sizeof( type ) )
1ab173
 
1ab173
 static CONST_DECL char * prformat( CONST_DECL char *, int );
1ab173
 static int isnum( CONST_DECL char *, int, int );