From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] netpbm: Update to 10.73.41 Date: Tue, 21 Feb 2023 10:34:42 +0100 Message-ID: <20230221093442.514668-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6676574825940069219==" List-Id: --===============6676574825940069219== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Signed-off-by: Stefan Schantl --- netpbm/netpbm.nm | 42 +- netpbm/patches/netpbm-CAN-2005-2471.patch | 16 + netpbm/patches/netpbm-python3.patch | 21 + netpbm/patches/netpbm-security-code.patch | 1432 ++++++++++++++++++ netpbm/patches/netpbm-security-scripts.patch | 369 +++++ 5 files changed, 1871 insertions(+), 9 deletions(-) create mode 100644 netpbm/patches/netpbm-CAN-2005-2471.patch create mode 100644 netpbm/patches/netpbm-python3.patch create mode 100644 netpbm/patches/netpbm-security-code.patch create mode 100644 netpbm/patches/netpbm-security-scripts.patch diff --git a/netpbm/netpbm.nm b/netpbm/netpbm.nm index 32cb27c87..07c49295c 100644 --- a/netpbm/netpbm.nm +++ b/netpbm/netpbm.nm @@ -4,7 +4,7 @@ ############################################################################= ### =20 name =3D netpbm -version =3D 10.71.02 +version =3D 10.73.41 release =3D 1 =20 groups =3D System/Libraries @@ -19,28 +19,52 @@ description .ppm (portable pixmaps) and others. end =20 -sources =3D %{thisapp}.tar.xz +source_dl =3D https://netcologne.dl.sourceforge.net/project/netpbm/super_st= able/%{version}/ +sources =3D %{thisapp}.tgz =20 build requires + /usr/bin/perl + perl(English) + perl(Time::gmtime) flex - ghostscript libjpeg-devel libpng-devel libtiff-devel - libX11-devel libxml2-devel - perl + zlib-devel end =20 - build - yes "" | ./configure + prepare_cmds + # Create config file. + cp -avf config.mk.in config.mk + + # Enable fPIC. + echo 'CFLAGS_SHLIB =3D -fPIC' >> config.mk + + # Disable static libs. + echo 'STATICLIB_TOO =3D N' >> config.mk + + # Link to libtiff, libjpeg, libpng and libz. + echo 'TIFFLIB =3D libtiff.so' >> config.mk + echo 'JPEGLIB =3D libjpeg.so' >> config.mk + echo 'PNGLIB =3D libpng.so' >> config.mk + echo 'ZLIB =3D libz.so' >> config.mk =20 - make \ + # Define include directorys for the linked libraries. + echo 'TIFFHDR_DIR =3D %{includedir}' >> config.mk + echo 'JPEGHDR_DIR =3D %{includedir}' >> config.mk + echo 'PNGHDR_DIR =3D %{includedir}' >> config.mk + echo 'ZHDR_DIR =3D %{includedir}' >> config.mk + end + + build + make %{PARALLELISMFLAGS} \ LDFLAGS=3D"%{LDFLAGS} -L$(pwd)/pbm -L$(pwd)/pgm -L$(pwd)/pnm -L$(pwd)/ppm= " \ CFLAGS=3D"%{CFLAGS} -flax-vector-conversions -fno-strict-aliasing" \ LADD=3D"-lm" \ - LINUXSVGALIB=3D"NONE" + LINUXSVGALIB=3D"NONE" \ + X11LIB=3D"NONE" end =20 install diff --git a/netpbm/patches/netpbm-CAN-2005-2471.patch b/netpbm/patches/netpb= m-CAN-2005-2471.patch new file mode 100644 index 000000000..e4e93735b --- /dev/null +++ b/netpbm/patches/netpbm-CAN-2005-2471.patch @@ -0,0 +1,16 @@ +--- netpbm-10.29/converter/other/pstopnm.c.CAN-2005-2471 2005-08-15 02:39:46= .000000000 +0200 ++++ netpbm-10.29/converter/other/pstopnm.c 2005-08-16 15:38:15.000000000 +02= 00 +@@ -818,11 +818,11 @@ + ghostscriptProg, arg0, + deviceopt, outfileopt, gopt, ropt, textalphabitsopt, + "-q", "-dNOPAUSE",=20 +- "-dSAFER", "-"); ++ "-dPARANOIDSAFER", "-"); + } +=20 + execl(ghostscriptProg, arg0, deviceopt, outfileopt, gopt, ropt,=20 +- textalphabitsopt, "-q", "-dNOPAUSE", "-dSAFER", "-", NULL); ++ textalphabitsopt, "-q", "-dNOPAUSE", "-dPARANOIDSAFER", "-", NULL); + =20 + pm_error("execl() of Ghostscript ('%s') failed, errno=3D%d (%s)", + ghostscriptProg, errno, strerror(errno)); diff --git a/netpbm/patches/netpbm-python3.patch b/netpbm/patches/netpbm-pyth= on3.patch new file mode 100644 index 000000000..d383b17cb --- /dev/null +++ b/netpbm/patches/netpbm-python3.patch @@ -0,0 +1,21 @@ +diff -Nur a/buildtools/makeman b/buildtools/makeman +--- a/buildtools/makeman 2019-06-29 01:07:55.000000000 +0200 ++++ b/buildtools/makeman 2023-02-21 09:06:40.587559363 +0100 +@@ -1,4 +1,4 @@ +-#!/usr/bin/python ++#!/usr/bin/python3 + # + # makeman -- compile netpbm's stereotyped HTML to troff markup + # +diff -Nur a/buildtools/manpage.mk b/buildtools/manpage.mk +--- a/buildtools/manpage.mk 2019-06-29 01:07:55.000000000 +0200 ++++ b/buildtools/manpage.mk 2023-02-21 09:07:20.566188386 +0100 +@@ -377,7 +377,7 @@ +=20 + # Make man pages -- reports bad lines to standard error. + manpages: +- @python $(MAKEMAN) -d $(USERGUIDE) index.html $(HTMLMANUALS)=20 ++ @python3 $(MAKEMAN) -d $(USERGUIDE) index.html $(HTMLMANUALS)=20 + @mv index.1 netpbm.1 +=20 + # Make XML pages, and validate them. diff --git a/netpbm/patches/netpbm-security-code.patch b/netpbm/patches/netpb= m-security-code.patch new file mode 100644 index 000000000..9e2e259f5 --- /dev/null +++ b/netpbm/patches/netpbm-security-code.patch @@ -0,0 +1,1432 @@ +diff --git a/analyzer/pgmtexture.c b/analyzer/pgmtexture.c +index 0731733..635c58b 100644 +--- a/analyzer/pgmtexture.c ++++ b/analyzer/pgmtexture.c +@@ -98,6 +98,8 @@ vector(unsigned int const nl, +=20 + assert(nh >=3D nl); +=20 ++ overflow_add(nh - nl, 1); ++ =20 + MALLOCARRAY(v, (unsigned) (nh - nl + 1)); +=20 + if (v =3D=3D NULL) +@@ -129,6 +131,7 @@ matrix (unsigned int const nrl, + assert(nrh >=3D nrl); +=20 + /* allocate pointers to rows */ ++ overflow_add(nrh - nrl, 1); + MALLOCARRAY(m, (unsigned) (nrh - nrl + 1)); + if (m =3D=3D NULL) + pm_error("Unable to allocate memory for a matrix."); +@@ -137,6 +140,7 @@ matrix (unsigned int const nrl, +=20 + assert (nch >=3D ncl); +=20 ++ overflow_add(nch - ncl, 1); + /* allocate rows and set pointers to them */ + for (i =3D nrl; i <=3D nrh; ++i) { + MALLOCARRAY(m[i], (unsigned) (nch - ncl + 1)); +diff --git a/converter/other/gemtopnm.c b/converter/other/gemtopnm.c +index aac7479..5f1a51a 100644 +--- a/converter/other/gemtopnm.c ++++ b/converter/other/gemtopnm.c +@@ -106,6 +106,7 @@ main(argc, argv) +=20 + pnm_writepnminit( stdout, cols, rows, MAXVAL, type, 0 ); +=20 ++ overflow_add(cols, padright); + {=20 + /* allocate input row data structure */ + int plane; +diff --git a/converter/other/jpegtopnm.c b/converter/other/jpegtopnm.c +index ab3b18e..c324b86 100644 +--- a/converter/other/jpegtopnm.c ++++ b/converter/other/jpegtopnm.c +@@ -861,6 +861,8 @@ convertImage(FILE * const ofP, + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfoP); +=20 ++ overflow2(cinfoP->output_width, cinfoP->output_components); ++ + /* Start decompressor */ + jpeg_start_decompress(cinfoP); +=20 +diff --git a/converter/other/pbmtopgm.c b/converter/other/pbmtopgm.c +index 69b20fb..382a487 100644 +--- a/converter/other/pbmtopgm.c ++++ b/converter/other/pbmtopgm.c +@@ -47,6 +47,7 @@ main(int argc, char *argv[]) { + "than the image height (%u rows)", height, rows); +=20 + outrow =3D pgm_allocrow(cols) ; ++ overflow2(width, height); + maxval =3D MIN(PGM_OVERALLMAXVAL, width*height); + pgm_writepgminit(stdout, cols, rows, maxval, 0) ; +=20 +diff --git a/converter/other/pnmtoddif.c b/converter/other/pnmtoddif.c +index ae8c852..9ee037b 100644 +--- a/converter/other/pnmtoddif.c ++++ b/converter/other/pnmtoddif.c +@@ -632,6 +632,7 @@ main(int argc, char *argv[]) { + switch (PNM_FORMAT_TYPE(format)) { + case PBM_TYPE: + ip.bits_per_pixel =3D 1; ++ overflow_add(cols, 7); + ip.bytes_per_line =3D (cols + 7) / 8; + ip.spectral =3D 2; + ip.components =3D 1; +@@ -647,6 +648,7 @@ main(int argc, char *argv[]) { + ip.polarity =3D 2; + break; + case PPM_TYPE: ++ overflow2(cols, 3); + ip.bytes_per_line =3D 3 * cols; + ip.bits_per_pixel =3D 24; + ip.spectral =3D 5; +diff --git a/converter/other/pnmtojpeg.c b/converter/other/pnmtojpeg.c +index ce231c9..1279040 100644 +--- a/converter/other/pnmtojpeg.c ++++ b/converter/other/pnmtojpeg.c +@@ -605,7 +605,11 @@ read_scan_script(j_compress_ptr const cinfo, + want JPOOL_PERMANENT. =20 + */ + const unsigned int scan_info_size =3D nscans * sizeof(jpeg_scan_inf= o); +- jpeg_scan_info * const scan_info =3D=20 ++ const jpeg_scan_info * scan_info; ++ =20 ++ overflow2(nscans, sizeof(jpeg_scan_info)); ++ =20 ++ scan_info =3D + (jpeg_scan_info *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + scan_info_size); +@@ -937,6 +941,8 @@ compute_rescaling_array(JSAMPLE ** const rescale_p, cons= t pixval maxval, + const long half_maxval =3D maxval / 2; + long val; +=20 ++ overflow_add(maxval, 1); ++ overflow2(maxval+1, sizeof(JSAMPLE)); + *rescale_p =3D (JSAMPLE *) + (cinfo.mem->alloc_small) ((j_common_ptr) &cinfo, JPOOL_IMAGE, + (size_t) (((long) maxval + 1L) *=20 +@@ -1015,6 +1021,7 @@ convert_scanlines(struct jpeg_compress_struct * const = cinfo_p, + */ +=20 + /* Allocate the libpnm output and compressor input buffers */ ++ overflow2(cinfo_p->image_width, cinfo_p->input_components); + buffer =3D (*cinfo_p->mem->alloc_sarray) + ((j_common_ptr) cinfo_p, JPOOL_IMAGE, + (unsigned int) cinfo_p->image_width * cinfo_p->input_components,=20 +diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c +index 6cd6be9..8a7d25a 100644 +--- a/converter/other/pnmtops.c ++++ b/converter/other/pnmtops.c +@@ -292,17 +292,21 @@ parseCommandLine(int argc, const char ** argv, + validateCompDimension(width, 72, "-width value"); + validateCompDimension(height, 72, "-height value"); + =20 ++ overflow2(width, 72); + cmdlineP->width =3D width * 72; ++ overflow2(height, 72); + cmdlineP->height =3D height * 72; +=20 + if (imagewidthSpec) { + validateCompDimension(imagewidth, 72, "-imagewidth value"); ++ overflow2(imagewidth, 72); + cmdlineP->imagewidth =3D imagewidth * 72; + } + else + cmdlineP->imagewidth =3D 0; + if (imageheightSpec) { +- validateCompDimension(imagewidth, 72, "-imageheight value"); ++ validateCompDimension(imageheight, 72, "-imageheight value"); ++ overflow2(imageheight, 72); + cmdlineP->imageheight =3D imageheight * 72; + } + else +diff --git a/converter/other/rletopnm.c b/converter/other/rletopnm.c +index 9995914..058278c 100644 +--- a/converter/other/rletopnm.c ++++ b/converter/other/rletopnm.c +@@ -19,6 +19,8 @@ + * If you modify this software, you should include a notice giving the + * name of the person performing the modification, the date of modification, + * and the reason for such modification. ++ * ++ * 2002-12-19: Fix maths wrapping bugs. Alan Cox + */ + /* + * rletopnm - A conversion program to convert from Utah's "rle" image format +diff --git a/converter/other/sirtopnm.c b/converter/other/sirtopnm.c +index fafcc91..9fe49d0 100644 +--- a/converter/other/sirtopnm.c ++++ b/converter/other/sirtopnm.c +@@ -69,6 +69,7 @@ char* argv[]; + } + break; + case PPM_TYPE: ++ overflow3(cols, rows, 3); + picsize =3D cols * rows * 3; + planesize =3D cols * rows; + if ( !( sirarray =3D (unsigned char*) malloc( picsize ) ) )=20 +diff --git a/converter/other/tifftopnm.c b/converter/other/tifftopnm.c +index 0d6494f..19e9e38 100644 +--- a/converter/other/tifftopnm.c ++++ b/converter/other/tifftopnm.c +@@ -1309,7 +1309,9 @@ convertRasterByRows(pnmOut * const pnmOutP, + if (scanbuf =3D=3D NULL) + pm_error("can't allocate memory for scanline buffer"); +=20 +- MALLOCARRAY(samplebuf, cols * spp); ++ /* samplebuf is unsigned int * !!! */ ++ samplebuf =3D (unsigned int *) malloc3(cols , sizeof(unsigned int) , sp= p); ++ + if (samplebuf =3D=3D NULL) + pm_error("can't allocate memory for row buffer"); +=20 +diff --git a/converter/other/xwdtopnm.c b/converter/other/xwdtopnm.c +index 45d66b4..c914481 100644 +--- a/converter/other/xwdtopnm.c ++++ b/converter/other/xwdtopnm.c +@@ -209,6 +209,10 @@ processX10Header(X10WDFileHeader * const h10P, + *colorsP =3D pnm_allocrow(2); + PNM_ASSIGN1((*colorsP)[0], 0); + PNM_ASSIGN1((*colorsP)[1], *maxvalP); ++ overflow_add(h10P->pixmap_width, 15); ++ if(h10P->pixmap_width < 0) ++ pm_error("assert: negative width"); ++ overflow2((((h10P->pixmap_width + 15) / 16) * 16 - h10P->pixmap_wid= th), 8); + *padrightP =3D + (((h10P->pixmap_width + 15) / 16) * 16 - h10P->pixmap_width) * = 8; + *bits_per_itemP =3D 16; +@@ -634,6 +638,7 @@ processX11Header(X11WDFileHeader * const h11P, +=20 + *colsP =3D h11FixedP->pixmap_width; + *rowsP =3D h11FixedP->pixmap_height; ++ overflow2(h11FixedP->bytes_per_line, 8); + *padrightP =3D + h11FixedP->bytes_per_line * 8 - + h11FixedP->pixmap_width * h11FixedP->bits_per_pixel; +diff --git a/converter/pbm/mdatopbm.c b/converter/pbm/mdatopbm.c +index d8e0657..12c7468 100644 +--- a/converter/pbm/mdatopbm.c ++++ b/converter/pbm/mdatopbm.c +@@ -245,10 +245,13 @@ main(int argc, char **argv) { + pm_readlittleshort(infile, &yy); nInCols =3D yy; + } + =20 ++ overflow2(nOutCols, 8); + nOutCols =3D 8 * nInCols; + nOutRows =3D nInRows; +- if (bScale)=20 ++ if (bScale) { ++ overflow2(nOutRows, 2); + nOutRows *=3D 2; ++ } +=20 + data =3D pbm_allocarray(nOutCols, nOutRows); + =20 +diff --git a/converter/pbm/mgrtopbm.c b/converter/pbm/mgrtopbm.c +index 9f7004a..60e8477 100644 +--- a/converter/pbm/mgrtopbm.c ++++ b/converter/pbm/mgrtopbm.c +@@ -65,6 +65,8 @@ readMgrHeader(FILE * const ifP, + pad =3D 0; /* should never reach here */ + } +=20 ++ overflow_add(*colsP, pad); ++ + interpHdrWidth (head, colsP); + interpHdrHeight(head, rowsP); + =20 +diff --git a/converter/pbm/pbmto4425.c b/converter/pbm/pbmto4425.c +index 1d97ac6..c4c8cbb 100644 +--- a/converter/pbm/pbmto4425.c ++++ b/converter/pbm/pbmto4425.c +@@ -2,6 +2,7 @@ +=20 + #include "nstring.h" + #include "pbm.h" ++#include +=20 + static char bit_table[2][3] =3D { + {1, 4, 0x10}, +@@ -160,7 +161,7 @@ main(int argc, char * argv[]) { + xres =3D vmap_width * 2; + yres =3D vmap_height * 3; +=20 +- vmap =3D malloc(vmap_width * vmap_height * sizeof(char)); ++ vmap =3D malloc3(vmap_width, vmap_height, sizeof(char)); + if(vmap =3D=3D NULL) + { + pm_error( "Cannot allocate memory" ); +diff --git a/converter/pbm/pbmtogem.c b/converter/pbm/pbmtogem.c +index 9eab041..13b0257 100644 +--- a/converter/pbm/pbmtogem.c ++++ b/converter/pbm/pbmtogem.c +@@ -79,6 +79,7 @@ putinit (int const rows, int const cols) + bitsperitem =3D 0; + bitshift =3D 7; + outcol =3D 0; ++ overflow_add(cols, 7); + outmax =3D (cols + 7) / 8; + outrow =3D (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char)); + lastrow =3D (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char)= ); +diff --git a/converter/pbm/pbmtogo.c b/converter/pbm/pbmtogo.c +index 23b2ee9..d2ee91f 100644 +--- a/converter/pbm/pbmtogo.c ++++ b/converter/pbm/pbmtogo.c +@@ -158,6 +158,7 @@ main(int argc, + bitrow =3D pbm_allocrow(cols); +=20 + /* Round cols up to the nearest multiple of 8. */ ++ overflow_add(cols, 7); + rucols =3D ( cols + 7 ) / 8; + bytesperrow =3D rucols; /* GraphOn uses bytes */ + rucols =3D rucols * 8; +diff --git a/converter/pbm/pbmtolj.c b/converter/pbm/pbmtolj.c +index 0cceb4f..fdab6df 100644 +--- a/converter/pbm/pbmtolj.c ++++ b/converter/pbm/pbmtolj.c +@@ -120,7 +120,11 @@ parseCommandLine(int argc, char ** argv, + static void + allocateBuffers(unsigned int const cols) { +=20 ++ overflow_add(cols, 8); + rowBufferSize =3D (cols + 7) / 8; ++ overflow_add(rowBufferSize, 128); ++ overflow_add(rowBufferSize, rowBufferSize+128); ++ overflow_add(rowBufferSize+10, rowBufferSize/8); + packBufferSize =3D rowBufferSize + (rowBufferSize + 127) / 128 + 1; + deltaBufferSize =3D rowBufferSize + rowBufferSize / 8 + 10; +=20 +diff --git a/converter/pbm/pbmtomda.c b/converter/pbm/pbmtomda.c +index 3ad5149..9efe5cf 100644 +--- a/converter/pbm/pbmtomda.c ++++ b/converter/pbm/pbmtomda.c +@@ -179,6 +179,7 @@ int main(int argc, char **argv) + =20 + nOutRowsUnrounded =3D bScale ? nInRows/2 : nInRows; +=20 ++ overflow_add(nOutRowsUnrounded, 3); + nOutRows =3D ((nOutRowsUnrounded + 3) / 4) * 4; + /* MDA wants rows a multiple of 4 */ =20 + nOutCols =3D nInCols / 8; +diff --git a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c +index 2f8a42b..1c8d236 100644 +--- a/converter/pbm/pbmtoppa/pbm.c ++++ b/converter/pbm/pbmtoppa/pbm.c +@@ -106,6 +106,7 @@ int pbm_readline(pbm_stat* pbm,unsigned char* data) + return 0; +=20 + case P4: ++ overflow_add(pbm->width, 7); + tmp=3D(pbm->width+7)/8; + tmp2=3Dfread(data,1,tmp,pbm->fptr); + if(tmp2 =3D=3D tmp) +@@ -130,6 +131,7 @@ void pbm_unreadline (pbm_stat *pbm, void *data) + return; +=20 + pbm->unread =3D 1; ++ overflow_add(pbm->width, 7); + pbm->revdata =3D malloc ((pbm->width+7)/8); + memcpy (pbm->revdata, data, (pbm->width+7)/8); + pbm->current_line--; +diff --git a/converter/pbm/pbmtoppa/pbmtoppa.c b/converter/pbm/pbmtoppa/pbmt= oppa.c +index f43c08a..98e0284 100644 +--- a/converter/pbm/pbmtoppa/pbmtoppa.c ++++ b/converter/pbm/pbmtoppa/pbmtoppa.c +@@ -452,6 +452,7 @@ main(int argc, char *argv[]) { + pm_error("main(): unrecognized parameter '%s'", argv[argn]); + } +=20 ++ overflow_add(Width, 7); + Pwidth=3D(Width+7)/8; + printer.fptr=3Dout; +=20 +diff --git a/converter/pbm/pbmtoxbm.c b/converter/pbm/pbmtoxbm.c +index 14c6b85..362b70e 100644 +--- a/converter/pbm/pbmtoxbm.c ++++ b/converter/pbm/pbmtoxbm.c +@@ -351,6 +351,8 @@ convertRaster(FILE * const ifP, +=20 + unsigned char * bitrow; + unsigned int row; ++ =20 ++ overflow_add(cols, padright); +=20 + putinit(xbmVersion); +=20 +diff --git a/converter/pbm/pktopbm.c b/converter/pbm/pktopbm.c +index 712f339..b6fcb02 100644 +--- a/converter/pbm/pktopbm.c ++++ b/converter/pbm/pktopbm.c +@@ -280,6 +280,7 @@ main(int argc, char *argv[]) { + if (flagbyte =3D=3D 7) { /* long form preamble */ + integer packetlength =3D get32() ; /* character packet lengt= h */ + car =3D get32() ; /* character number */ ++ overflow_add(packetlength, pktopbm_pkloc); + endofpacket =3D packetlength + pktopbm_pkloc; + /* calculate end of packet */ + if ((car >=3D MAXPKCHAR) || !filename[car]) { +diff --git a/converter/pbm/thinkjettopbm.l b/converter/pbm/thinkjettopbm.l +index 5de4f2b..7f31de5 100644 +--- a/converter/pbm/thinkjettopbm.l ++++ b/converter/pbm/thinkjettopbm.l +@@ -114,7 +114,9 @@ DIG [0-9] + \033\*b{DIG}+W { + int l; + if (rowCount >=3D rowCapacity) { +- rowCapacity +=3D 100; ++ overflow_add(rowCapacity, 100); ++ rowCapacity +=3D 100; ++ overflow2(rowCapacity, sizeof *rows); + rows =3D realloc (rows, rowCapacity * sizeo= f *rows); + if (rows =3D=3D NULL) + pm_error ("Out of memory."); +@@ -226,6 +228,8 @@ yywrap (void) + /* + * Quite simple since ThinkJet bit arrangement matches PBM + */ ++ ++ overflow2(maxRowLength, 8); + pbm_writepbminit(stdout, maxRowLength*8, rowCount, 0); +=20 + packed_bitrow =3D malloc(maxRowLength); +diff --git a/converter/pbm/ybmtopbm.c b/converter/pbm/ybmtopbm.c +index 2a42908..cf1ff03 100644 +--- a/converter/pbm/ybmtopbm.c ++++ b/converter/pbm/ybmtopbm.c +@@ -43,6 +43,7 @@ getinit(FILE * const ifP, + pm_error("EOF / read error"); +=20 + *depthP =3D 1; ++ overflow_add(*colsP, 15); + } +=20 +=20 +diff --git a/converter/pgm/lispmtopgm.c b/converter/pgm/lispmtopgm.c +index 40dd3fb..b5469f7 100644 +--- a/converter/pgm/lispmtopgm.c ++++ b/converter/pgm/lispmtopgm.c +@@ -58,6 +58,7 @@ main( argc, argv ) + pm_error( "depth (%d bits) is too large", depth); +=20 + pgm_writepgminit( stdout, cols, rows, (gray) maxval, 0 ); ++ overflow_add(cols, 7); + grayrow =3D pgm_allocrow( ( cols + 7 ) / 8 * 8 ); +=20 + for ( row =3D 0; row < rows; ++row ) +@@ -102,6 +103,8 @@ getinit( file, colsP, rowsP, depthP, padrightP ) + =20 + if ( *depthP =3D=3D 0 ) + *depthP =3D 1; /* very old file */ ++ ++ overflow_add((int)colsP, 31); + =20 + *padrightP =3D ( ( *colsP + 31 ) / 32 ) * 32 - *colsP; + =20 +diff --git a/converter/pgm/psidtopgm.c b/converter/pgm/psidtopgm.c +index 07417d1..25bb311 100644 +--- a/converter/pgm/psidtopgm.c ++++ b/converter/pgm/psidtopgm.c +@@ -78,6 +78,7 @@ main(int argc, + pm_error("bits/sample (%d) is too large.", bitspersample); +=20 + pgm_writepgminit(stdout, cols, rows, maxval, 0); ++ overflow_add(cols, 7); + grayrow =3D pgm_allocrow((cols + 7) / 8 * 8); + for (row =3D 0; row < rows; ++row) { + unsigned int col; +diff --git a/converter/ppm/Makefile b/converter/ppm/Makefile +index 09f05cd..f68170f 100644 +--- a/converter/ppm/Makefile ++++ b/converter/ppm/Makefile +@@ -11,7 +11,7 @@ SUBDIRS =3D hpcdtoppm +=20 + PORTBINARIES =3D 411toppm eyuvtoppm gouldtoppm ilbmtoppm imgtoppm \ + leaftoppm mtvtoppm neotoppm \ +- pcxtoppm pc1toppm pi1toppm picttoppm pjtoppm \ ++ pcxtoppm pc1toppm pi1toppm pjtoppm \ + ppmtoacad ppmtoapplevol ppmtoarbtxt ppmtoascii \ + ppmtobmp ppmtoeyuv ppmtogif ppmtoicr ppmtoilbm \ + ppmtoleaf ppmtolj ppmtomitsu ppmtoneo \ +diff --git a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c +index 662be0b..2a86efc 100644 +--- a/converter/ppm/ilbmtoppm.c ++++ b/converter/ppm/ilbmtoppm.c +@@ -606,6 +606,7 @@ decode_row(FILE * const ifP, + rawtype *chp; +=20 + cols =3D bmhdP->w; ++ overflow_add(cols, 15); + bytes =3D RowBytes(cols); + for( plane =3D 0; plane < nPlanes; plane++ ) { + int mask; +@@ -693,6 +694,23 @@ decode_mask(FILE * const ifP, + Multipalette handling + **************************************************************************= **/ +=20 ++static void * ++xmalloc2(x, y) ++ int x; ++ int y; ++{ ++ void *mem; ++ ++ overflow2(x,y); ++ if( x * y =3D=3D 0 ) ++ return NULL; ++ ++ mem =3D malloc2(x,y); ++ if( mem =3D=3D NULL ) ++ pm_error("out of memory allocating %d bytes", x * y); ++ return mem; ++} ++ +=20 + static void + multi_adjust(cmap, row, palchange) +@@ -1355,6 +1373,9 @@ dcol_to_ppm(FILE * const ifP, + if( redmaxval !=3D maxval || greenmaxval !=3D maxval || bluemaxval !=3D= maxval ) + pm_message("scaling colors to %d bits", pm_maxvaltobits(maxval)); + =20 ++ overflow_add(redmaxval, 1); ++ overflow_add(greenmaxval, 1); ++ overflow_add(bluemaxval, 1); + MALLOCARRAY_NOFAIL(redtable, redmaxval +1); + MALLOCARRAY_NOFAIL(greentable, greenmaxval +1); + MALLOCARRAY_NOFAIL(bluetable, bluemaxval +1); +@@ -1784,7 +1805,9 @@ PCHG_ConvertSmall(PCHG, cmap, mask, datasize) + ChangeCount32 =3D *data++; + datasize -=3D 2; +=20 ++ overflow_add(ChangeCount16, ChangeCount32); + changes =3D ChangeCount16 + ChangeCount32; ++ overflow_add(changes, 1); + for( i =3D 0; i < changes; i++ ) { + if( totalchanges >=3D PCHG->TotalChanges ) goto fail; + if( datasize < 2 ) goto fail; +@@ -2049,6 +2072,9 @@ read_pchg(FILE * const ifP, + cmap->mp_change[i] =3D NULL; + if( PCHG.StartLine < 0 ) { + int nch; ++ if(PCHG.MaxReg < PCHG.MinReg) ++ pm_error("assert: MinReg > MaxReg"); ++ overflow_add(PCHG.MaxReg-PCHG.MinReg, 2); + nch =3D PCHG.MaxReg - PCHG.MinReg +1; + MALLOCARRAY_NOFAIL(cmap->mp_init, nch + 1); + for( i =3D 0; i < nch; i++ ) +@@ -2125,6 +2151,7 @@ process_body( FILE * const ifP, + if (typeid =3D=3D ID_ILBM) { + int isdeep; +=20 ++ overflow_add(bmhdP->w, 15); + MALLOCARRAY_NOFAIL(ilbmrow, RowBytes(bmhdP->w)); + *viewportmodesP |=3D fakeviewport; /* -isham/-isehb */ +=20 +diff --git a/converter/ppm/imgtoppm.c b/converter/ppm/imgtoppm.c +index 7078b88..eb8509e 100644 +--- a/converter/ppm/imgtoppm.c ++++ b/converter/ppm/imgtoppm.c +@@ -84,6 +84,7 @@ main(int argc, char ** argv) { + len =3D atoi((char*) buf ); + if ( fread( buf, len, 1, ifp ) !=3D 1 ) + pm_error( "bad colormap buf" ); ++ overflow2(cmaplen, 3); + if ( cmaplen * 3 !=3D len ) + { + pm_message( +@@ -105,6 +106,7 @@ main(int argc, char ** argv) { + pm_error( "bad pixel data header" ); + buf[8] =3D '\0'; + len =3D atoi((char*) buf ); ++ overflow2(cols, rows); + if ( len !=3D cols * rows ) + pm_message( + "pixel data length (%d) does not match image size (%d)", +diff --git a/converter/ppm/pcxtoppm.c b/converter/ppm/pcxtoppm.c +index e252ba2..270ae3b 100644 +--- a/converter/ppm/pcxtoppm.c ++++ b/converter/ppm/pcxtoppm.c +@@ -409,6 +409,7 @@ pcx_planes_to_pixels(pixels, bitplanes, bytesperline, pl= anes, bitsperpixel) + /* + * clear the pixel buffer + */ ++ overflow2(bytesperline, 8); + npixels =3D (bytesperline * 8) / bitsperpixel; + p =3D pixels; + while (--npixels >=3D 0) +@@ -470,6 +471,7 @@ pcx_16col_to_ppm(FILE * const ifP, + } +=20 + /* BytesPerLine should be >=3D BitsPerPixel * cols / 8 */ ++ overflow2(BytesPerLine, 8); + rawcols =3D BytesPerLine * 8 / BitsPerPixel; + if (headerCols > rawcols) { + pm_message("warning - BytesPerLine =3D %d, " +diff --git a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c +index 828d527..8cdb7b3 100644 +--- a/converter/ppm/picttoppm.c ++++ b/converter/ppm/picttoppm.c +@@ -1,3 +1,4 @@ ++#error "Unfixable. Don't ship me" + /* + * picttoppm.c -- convert a MacIntosh PICT file to PPM format. + * +diff --git a/converter/ppm/pjtoppm.c b/converter/ppm/pjtoppm.c +index 7b694fb..62ce77e 100644 +--- a/converter/ppm/pjtoppm.c ++++ b/converter/ppm/pjtoppm.c +@@ -127,20 +127,22 @@ main(argc, argv) + case 'V': /* send plane */ + case 'W': /* send last plane */ + if (rows =3D=3D -1 || r >=3D rows || image =3D=3D NULL)= { +- if (rows =3D=3D -1 || r >=3D rows) ++ if (rows =3D=3D -1 || r >=3D rows) { ++ overflow_add(rows, 100); + rows +=3D 100; ++ } ++ + if (image =3D=3D NULL) { +- MALLOCARRAY(image, rows * planes); +- MALLOCARRAY(imlen, rows * planes); ++ image =3D (unsigned char **) ++ malloc3(rows , planes , sizeof(unsigned cha= r *)); ++ imlen =3D (int *) malloc3(rows , planes, sizeo= f(int)); + } + else { +- image =3D (unsigned char **)=20 +- realloc(image,=20 +- rows * planes *=20 +- sizeof(unsigned char *)); +- imlen =3D (int *)=20 +- realloc(imlen, rows * planes * sizeof(int)); +- } ++ overflow2(rows,planes); ++ image =3D (unsigned char **) ++ realloc2(image, rows * planes, ++ sizeof(unsigned char *)); ++ imlen =3D (int *) realloc2(imlen, rows * planes= , sizeof(int)); } + } + if (image =3D=3D NULL || imlen =3D=3D NULL) + pm_error("out of memory"); +@@ -212,8 +214,10 @@ main(argc, argv) + for (i =3D 0, c =3D 0; c < imlen[p + r * planes]; c +=3D 2) + for (cmd =3D image[p + r * planes][c], + val =3D image[p + r * planes][c+1];=20 +- cmd >=3D 0 && i < newcols; cmd--, i++)=20 ++ cmd >=3D 0 && i < newcols; cmd--, i++) { + buf[i] =3D val; ++ overflow_add(i, 1); ++ } + cols =3D cols > i ? cols : i; + free(image[p + r * planes]); + /*=20 +@@ -224,6 +228,7 @@ main(argc, argv) + image[p + r * planes] =3D (unsigned char *) realloc(buf, i); + } + } ++ overflow2(cols, 8); + cols *=3D 8; + } + =20 +diff --git a/converter/ppm/ppmtoeyuv.c b/converter/ppm/ppmtoeyuv.c +index f5ce115..6f072be 100644 +--- a/converter/ppm/ppmtoeyuv.c ++++ b/converter/ppm/ppmtoeyuv.c +@@ -114,6 +114,7 @@ create_multiplication_tables(const pixval maxval) { +=20 + int index; +=20 ++ overflow_add(maxval, 1); + MALLOCARRAY_NOFAIL(mult299 , maxval+1); + MALLOCARRAY_NOFAIL(mult587 , maxval+1); + MALLOCARRAY_NOFAIL(mult114 , maxval+1); +diff --git a/converter/ppm/ppmtolj.c b/converter/ppm/ppmtolj.c +index 7ed814e..b4e7db1 100644 +--- a/converter/ppm/ppmtolj.c ++++ b/converter/ppm/ppmtolj.c +@@ -182,6 +182,7 @@ int main(int argc, char *argv[]) { + ppm_readppminit( ifp, &cols, &rows, &maxval, &format ); + pixelrow =3D ppm_allocrow( cols ); +=20 ++ overflow2(cols, 6); + obuf =3D (unsigned char *) pm_allocrow(cols * 3, sizeof(unsigned char)); + cbuf =3D (unsigned char *) pm_allocrow(cols * 6, sizeof(unsigned char)); + if (mode =3D=3D C_TRANS_MODE_DELTA) +diff --git a/converter/ppm/ppmtomitsu.c b/converter/ppm/ppmtomitsu.c +index e59f09b..1d2be20 100644 +--- a/converter/ppm/ppmtomitsu.c ++++ b/converter/ppm/ppmtomitsu.c +@@ -685,6 +685,8 @@ main(int argc, char * argv[]) { + medias =3D MSize_User; +=20 + if (dpi300) { ++ overflow2(medias.maxcols, 2); ++ overflow2(medias.maxrows, 2); + medias.maxcols *=3D 2; + medias.maxrows *=3D 2; + } +diff --git a/converter/ppm/ppmtopcx.c b/converter/ppm/ppmtopcx.c +index fa68edc..97dfb2b 100644 +--- a/converter/ppm/ppmtopcx.c ++++ b/converter/ppm/ppmtopcx.c +@@ -425,6 +425,8 @@ ppmTo16ColorPcx(pixel ** const pixels, + else Planes =3D 1; + } + } ++ overflow2(BitsPerPixel, cols); ++ overflow_add(BitsPerPixel * cols, 7); + BytesPerLine =3D ((cols * BitsPerPixel) + 7) / 8; + MALLOCARRAY_NOFAIL(indexRow, cols); + MALLOCARRAY_NOFAIL(planesrow, BytesPerLine); +diff --git a/converter/ppm/ppmtopict.c b/converter/ppm/ppmtopict.c +index 034e705..4541387 100644 +--- a/converter/ppm/ppmtopict.c ++++ b/converter/ppm/ppmtopict.c +@@ -450,6 +450,8 @@ main(int argc, const char ** argv) { + putShort(stdout, 0); /* mode */ +=20 + /* Finally, write out the data. */ ++ overflow_add(cols/MAX_COUNT, 1); ++ overflow_add(cols, cols/MAX_COUNT+1); + outBuf =3D malloc((unsigned)(cols+cols/MAX_COUNT+1)); + for (row =3D 0, oc =3D 0; row < rows; ++row) { + unsigned int rowSize; +diff --git a/converter/ppm/ppmtopj.c b/converter/ppm/ppmtopj.c +index d116773..fc84cac 100644 +--- a/converter/ppm/ppmtopj.c ++++ b/converter/ppm/ppmtopj.c +@@ -179,6 +179,7 @@ char *argv[]; + pixels =3D ppm_readppm( ifp, &cols, &rows, &maxval ); +=20 + pm_close( ifp ); ++ overflow2(cols,2); + obuf =3D (unsigned char *) pm_allocrow(cols, sizeof(unsigned char)); + cbuf =3D (unsigned char *) pm_allocrow(cols * 2, sizeof(unsigned char)); +=20 +diff --git a/converter/ppm/ppmtopjxl.c b/converter/ppm/ppmtopjxl.c +index ddf4963..b2c7e8e 100644 +--- a/converter/ppm/ppmtopjxl.c ++++ b/converter/ppm/ppmtopjxl.c +@@ -306,6 +306,9 @@ main(int argc, const char * argv[]) { + if (maxval > PCL_MAXVAL) + pm_error("color range too large; reduce with ppmcscale"); +=20 ++ if (cols < 0 || rows < 0) ++ pm_error("negative size is not possible"); ++ + /* Figure out the colormap. */ + pm_message("Computing colormap..."); + chv =3D ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &colors); +@@ -325,6 +328,8 @@ main(int argc, const char * argv[]) { + case 0: /* direct mode (no palette) */ + bpp =3D bitsperpixel(maxval); /* bits per pixel */ + bpg =3D bpp; bpb =3D bpp; ++ overflow2(bpp, 3); ++ overflow_add(bpp*3, 7); + bpp =3D (bpp*3+7)>>3; /* bytes per pixel now */ + bpr =3D (bpp<<3)-bpg-bpb;=20 + bpp *=3D cols; /* bytes per row now */ +@@ -334,9 +339,13 @@ main(int argc, const char * argv[]) { + case 3: case 7: pclindex++; + default: + bpp =3D 8/pclindex; ++ overflow_add(cols, bpp); ++ if(bpp =3D=3D 0) ++ pm_error("assert: no bpp"); + bpp =3D (cols+bpp-1)/bpp; /* bytes per row */ + } + } ++ overflow2(bpp,2); + inrow =3D (char *)malloc((unsigned)bpp); + outrow =3D (char *)malloc((unsigned)bpp*2); + runcnt =3D (signed char *)malloc((unsigned)bpp); +diff --git a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c +index c673798..af2b445 100644 +--- a/converter/ppm/ppmtowinicon.c ++++ b/converter/ppm/ppmtowinicon.c +@@ -12,6 +12,7 @@ +=20 + #include + #include ++#include +=20 + #include "pm_c_util.h" + #include "winico.h" +@@ -214,6 +215,7 @@ createAndBitmap (gray ** const ba, int const cols, int c= onst rows, + MALLOCARRAY_NOFAIL(rowData, rows); + icBitmap->xBytes =3D xBytes; + icBitmap->data =3D rowData; ++ overflow2(xBytes, rows); + icBitmap->size =3D xBytes * rows; + for (y=3D0;yxBytes =3D xBytes; + icBitmap->data =3D rowData; ++ overflow2(xBytes, rows); + icBitmap->size =3D xBytes * rows; +=20 + for (y=3D0;yxBytes =3D xBytes; + icBitmap->data =3D rowData; ++ overflow2(xBytes, rows); + icBitmap->size =3D xBytes * rows; +=20 + for (y=3D0;ybitcount =3D bpp; + entry->ih =3D createInfoHeader(entry, xorBitmap, andBitmap); + entry->colors =3D palette->colors; +- entry->size_in_bytes =3D=20 ++ overflow2(4, entry->color_count); ++ overflow_add(xorBitmap->size, andBitmap->size); ++ overflow_add(xorBitmap->size + andBitmap->size, 40); ++ overflow_add(xorBitmap->size + andBitmap->size + 40, 4 * entry->color_c= ount); ++ entry->size_in_bytes =3D + xorBitmap->size + andBitmap->size + 40 + (4 * entry->color_count); + if (verbose)=20 + pm_message("entry->size_in_bytes =3D %d + %d + %d =3D %d", +diff --git a/converter/ppm/ppmtoxpm.c b/converter/ppm/ppmtoxpm.c +index 38d9997..904c98d 100644 +--- a/converter/ppm/ppmtoxpm.c ++++ b/converter/ppm/ppmtoxpm.c +@@ -197,6 +197,7 @@ genNumstr(unsigned int const input, int const digits) { + unsigned int i; +=20 + /* Allocate memory for printed number. Abort if error. */ ++ overflow_add(digits, 1); + if (!(str =3D (char *) malloc(digits + 1))) + pm_error("out of memory"); +=20 +@@ -314,6 +315,7 @@ genCmap(colorhist_vector const chv, + unsigned int charsPerPixel; + unsigned int xpmMaxval; + =20 ++ if (includeTransparent) overflow_add(ncolors, 1); + MALLOCARRAY(cmap, cmapSize); + if (cmapP =3D=3D NULL) + pm_error("Out of memory allocating %u bytes for a color map.", +diff --git a/converter/ppm/qrttoppm.c b/converter/ppm/qrttoppm.c +index 935463e..653084c 100644 +--- a/converter/ppm/qrttoppm.c ++++ b/converter/ppm/qrttoppm.c +@@ -46,7 +46,7 @@ main( argc, argv ) +=20 + ppm_writeppminit( stdout, cols, rows, maxval, 0 ); + pixelrow =3D ppm_allocrow( cols ); +- buf =3D (unsigned char *) malloc( 3 * cols ); ++ buf =3D (unsigned char *) malloc2( 3 , cols ); + if ( buf =3D=3D (unsigned char *) 0 ) + pm_error( "out of memory" ); +=20 +diff --git a/converter/ppm/sldtoppm.c b/converter/ppm/sldtoppm.c +index 6ba4cb4..fc6a498 100644 +--- a/converter/ppm/sldtoppm.c ++++ b/converter/ppm/sldtoppm.c +@@ -464,6 +464,8 @@ slider(slvecfn slvec, + =20 + /* Allocate image buffer and clear it to black. */ + =20 ++ overflow_add(ixdots, 1); ++ overflow_add(iydots, 1); + pixels =3D ppm_allocarray(pixcols =3D ixdots + 1, pixrows =3D iydots + = 1); + PPM_ASSIGN(rgbcolor, 0, 0, 0); + ppmd_filledrectangle(pixels, pixcols, pixrows, pixmaxval, 0, 0, +diff --git a/converter/ppm/ximtoppm.c b/converter/ppm/ximtoppm.c +index ce5e639..a39b689 100644 +--- a/converter/ppm/ximtoppm.c ++++ b/converter/ppm/ximtoppm.c +@@ -160,6 +163,7 @@ ReadXimHeader(FILE * const in_fp, + if (header->nchannels =3D=3D 3 && header->bits_channel =3D=3D 8) + header->ncolors =3D 0; + else if (header->nchannels =3D=3D 1 && header->bits_channel =3D=3D 8) { ++ overflow2(header->ncolors, sizeof(Color)); + header->colors =3D (Color *)calloc((unsigned int)header->ncolors, + sizeof(Color)); + if (header->colors =3D=3D NULL) { +diff --git a/editor/pamcut.c b/editor/pamcut.c +index 7c41af3..72df687 100644 +--- a/editor/pamcut.c ++++ b/editor/pamcut.c +@@ -655,6 +655,8 @@ cutOneImage(FILE * const ifP, +=20 + outpam =3D inpam; /* Initial value -- most fields should be same */ + outpam.file =3D ofP; ++ overflow_add(rightcol, 1); ++ overflow_add(bottomrow, 1); + outpam.width =3D rightcol - leftcol + 1; + outpam.height =3D bottomrow - toprow + 1; +=20 +diff --git a/editor/pbmreduce.c b/editor/pbmreduce.c +index f49c8d9..580e5e0 100644 +--- a/editor/pbmreduce.c ++++ b/editor/pbmreduce.c +@@ -94,6 +94,7 @@ main( argc, argv ) + if (halftone =3D=3D QT_FS) { + unsigned int col; + /* Initialize Floyd-Steinberg. */ ++ overflow_add(newcols, 2); + MALLOCARRAY(thiserr, newcols + 2); + MALLOCARRAY(nexterr, newcols + 2); + if (thiserr =3D=3D NULL || nexterr =3D=3D NULL) +diff --git a/editor/pnmgamma.c b/editor/pnmgamma.c +index b357b0d..ec612d3 100644 +--- a/editor/pnmgamma.c ++++ b/editor/pnmgamma.c +@@ -596,6 +596,7 @@ createGammaTables(enum transferFunction const transferFu= nction, + xelval ** const btableP) { +=20 + /* Allocate space for the tables. */ ++ overflow_add(maxval, 1); + MALLOCARRAY(*rtableP, maxval+1); + MALLOCARRAY(*gtableP, maxval+1); + MALLOCARRAY(*btableP, maxval+1); +diff --git a/editor/pnmhisteq.c b/editor/pnmhisteq.c +index 8af4201..0c8d6e5 100644 +--- a/editor/pnmhisteq.c ++++ b/editor/pnmhisteq.c +@@ -107,6 +107,7 @@ computeLuminosityHistogram(xel * const * const xels, + unsigned int pixelCount; + unsigned int * lumahist; +=20 ++ overflow_add(maxval, 1); + MALLOCARRAY(lumahist, maxval + 1); + if (lumahist =3D=3D NULL) + pm_error("Out of storage allocating array for %u histogram elements= ", +diff --git a/editor/pnmindex.csh b/editor/pnmindex.csh +index c6f1e84..c513a84 100755 +--- a/editor/pnmindex.csh ++++ b/editor/pnmindex.csh +@@ -1,5 +1,7 @@ + #!/bin/csh -f + # ++echo "Unsafe code, needs debugging, do not ship" ++exit 1 + # pnmindex - build a visual index of a bunch of anymaps + # + # Copyright (C) 1991 by Jef Poskanzer. +diff --git a/editor/pnmpad.c b/editor/pnmpad.c +index 1904b68..0797cf1 100644 +--- a/editor/pnmpad.c ++++ b/editor/pnmpad.c +@@ -527,6 +527,8 @@ main(int argc, const char ** argv) { +=20 + computePadSizes(cmdline, cols, rows, &lpad, &rpad, &tpad, &bpad); +=20 ++ overflow_add(cols, lpad); ++ overflow_add(cols + lpad, rpad); + newcols =3D cols + lpad + rpad; +=20 + if (PNM_FORMAT_TYPE(format) =3D=3D PBM_TYPE) +diff --git a/editor/pnmremap.c b/editor/pnmremap.c +index b2448cb..b924120 100644 +--- a/editor/pnmremap.c ++++ b/editor/pnmremap.c +@@ -428,6 +428,7 @@ initFserr(struct pam * const pamP, +=20 + unsigned int const fserrSize =3D pamP->width + 2; +=20 ++ overflow_add(pamP->width, 2); + fserrP->width =3D pamP->width; +=20 + MALLOCARRAY(fserrP->thiserr, pamP->depth); +@@ -465,6 +466,7 @@ floydInitRow(struct pam * const pamP, struct fserr * con= st fserrP) { +=20 + int col; + =20 ++ overflow_add(pamP->width, 2); + for (col =3D 0; col < pamP->width + 2; ++col) { + unsigned int plane; + for (plane =3D 0; plane < pamP->depth; ++plane)=20 +diff --git a/editor/pnmscalefixed.c b/editor/pnmscalefixed.c +index 884ca31..747cd8f 100644 +--- a/editor/pnmscalefixed.c ++++ b/editor/pnmscalefixed.c +@@ -214,6 +214,7 @@ compute_output_dimensions(const struct cmdline_info cmdl= ine, + const int rows, const int cols, + int * newrowsP, int * newcolsP) { +=20 ++ overflow2(rows, cols); + if (cmdline.pixels) { + if (rows * cols <=3D cmdline.pixels) { + *newrowsP =3D rows; +@@ -265,6 +266,8 @@ compute_output_dimensions(const struct cmdline_info cmdl= ine, +=20 + if (*newcolsP < 1) *newcolsP =3D 1; + if (*newrowsP < 1) *newrowsP =3D 1; ++ ++ overflow2(*newcolsP, *newrowsP); + } =20 +=20 +=20 +@@ -446,6 +449,9 @@ main(int argc, char **argv ) { + unfilled. We can address that by stretching, whereas the other + case would require throwing away some of the input. + */ ++ ++ overflow2(newcols, SCALE); ++ overflow2(newrows, SCALE); + sxscale =3D SCALE * newcols / cols; + syscale =3D SCALE * newrows / rows; +=20 +diff --git a/editor/ppmdither.c b/editor/ppmdither.c +index ec1b977..e701e09 100644 +--- a/editor/ppmdither.c ++++ b/editor/ppmdither.c +@@ -356,6 +356,11 @@ dithMatrix(unsigned int const dithPower) { + (dithDim * sizeof(*dithMat)) + /* pointers */ + (dithDim * dithDim * sizeof(**dithMat)); /* data */ + =20 ++ ++ overflow2(dithDim, sizeof(*dithMat)); ++ overflow3(dithDim, dithDim, sizeof(**dithMat)); ++ overflow_add(dithDim * sizeof(*dithMat), dithDim * dithDim * sizeof= (**dithMat)); ++ + dithMat =3D malloc(dithMatSize); + =20 + if (dithMat =3D=3D NULL)=20 +diff --git a/editor/specialty/pamoil.c b/editor/specialty/pamoil.c +index 6cb8d3a..6f4bde9 100644 +--- a/editor/specialty/pamoil.c ++++ b/editor/specialty/pamoil.c +@@ -112,6 +112,7 @@ main(int argc, char *argv[] ) { + tuples =3D pnm_readpam(ifp, &inpam, PAM_STRUCT_SIZE(tuple_type)); + pm_close(ifp); +=20 ++ overflow_add(inpam.maxval, 1); + MALLOCARRAY(hist, inpam.maxval + 1); + if (hist =3D=3D NULL) + pm_error("Unable to allocate memory for histogram."); +diff --git a/generator/pbmtext.c b/generator/pbmtext.c +index 9f4366d..445d718 100644 +--- a/generator/pbmtext.c ++++ b/generator/pbmtext.c +@@ -96,12 +96,14 @@ parseCommandLine(int argc, const char ** argv, + =20 + for (i =3D 1; i < argc; ++i) { + if (i > 1) { ++ overflow_add(totaltextsize, 1); + totaltextsize +=3D 1; + text =3D realloc(text, totaltextsize); + if (text =3D=3D NULL) + pm_error("out of memory allocating space for input text= "); + strcat(text, " "); +- }=20 ++ } ++ overflow_add(totaltextsize, strlen(argv[i])); + totaltextsize +=3D strlen(argv[i]); + text =3D realloc(text, totaltextsize); + if (text =3D=3D NULL) +@@ -712,6 +714,7 @@ getText(const char cmdline_text[], + pm_error("A line of input text is longer than %u characters= ." + "Cannot process.", (unsigned)sizeof(buf)-1); + if (lineCount >=3D maxlines) { ++ overflow2(maxlines, 2); + maxlines *=3D 2; + REALLOCARRAY(text_array, maxlines); + if (text_array =3D=3D NULL) +@@ -832,6 +835,7 @@ main(int argc, const char *argv[]) { + hmargin =3D fontP->maxwidth; + } else { + vmargin =3D fontP->maxheight; ++ overflow2(2, fontP->maxwidth); + hmargin =3D 2 * fontP->maxwidth; + } + } +diff --git a/lib/libpam.c b/lib/libpam.c +index cc6368e..4e10572 100644 +--- a/lib/libpam.c ++++ b/lib/libpam.c +@@ -224,8 +224,9 @@ allocPamRow(const struct pam * const pamP) { + unsigned int const bytesPerTuple =3D allocationDepth(pamP) * sizeof(sam= ple); + tuple * tuplerow; +=20 +- tuplerow =3D malloc(pamP->width * (sizeof(tuple *) + bytesPerTuple)); +- =20 ++ overflow_add(sizeof(tuple *), bytesPerTuple); ++ tuplerow =3D malloc2(pamP->width, (sizeof(tuple *) + bytesPerTuple)); ++ + if (tuplerow !=3D NULL) { + /* Now we initialize the pointers to the individual tuples + to make this a regulation C two dimensional array. =20 +diff --git a/lib/libpammap.c b/lib/libpammap.c +index 55e1d3f..04b1ba3 100644 +--- a/lib/libpammap.c ++++ b/lib/libpammap.c +@@ -108,7 +108,9 @@ allocTupleIntListItem(struct pam * const pamP) { + */ + struct tupleint_list_item * retval; +=20 +- unsigned int const size =3D=20 ++ overflow2(pamP->depth, sizeof(sample)); ++ overflow_add(sizeof(*retval)-sizeof(retval->tupleint.tuple), pamP->dept= h*sizeof(sample)); ++ unsigned int const size =3D + sizeof(*retval) - sizeof(retval->tupleint.tuple)=20 + + pamP->depth * sizeof(sample); +=20 +diff --git a/lib/libpm.c b/lib/libpm.c +index 4374bbe..5ab7f83 100644 +--- a/lib/libpm.c ++++ b/lib/libpm.c +@@ -841,5 +841,53 @@ pm_parse_height(const char * const arg) { + return height; + } +=20 ++/* ++ * Maths wrapping ++ */ +=20 ++void __overflow2(int a, int b) ++{ ++ if(a < 0 || b < 0) ++ pm_error("object too large"); ++ if(b =3D=3D 0) ++ return; ++ if(a > INT_MAX / b) ++ pm_error("object too large"); ++} ++ ++void overflow3(int a, int b, int c) ++{ ++ overflow2(a,b); ++ overflow2(a*b, c); ++} ++ ++void overflow_add(int a, int b) ++{ ++ if( a > INT_MAX - b) ++ pm_error("object too large"); ++} ++ ++void *malloc2(int a, int b) ++{ ++ overflow2(a, b); ++ if(a*b =3D=3D 0) ++ pm_error("Zero byte allocation"); ++ return malloc(a*b); ++} ++ ++void *malloc3(int a, int b, int c) ++{ ++ overflow3(a, b, c); ++ if(a*b*c =3D=3D 0) ++ pm_error("Zero byte allocation"); ++ return malloc(a*b*c); ++} ++ ++void *realloc2(void * a, int b, int c) ++{ ++ overflow2(b, c); ++ if(b*c =3D=3D 0) ++ pm_error("Zero byte allocation"); ++ return realloc(a, b*c); ++} +=20 +diff --git a/lib/pm.h b/lib/pm.h +index e9f1405..da54391 100644 +--- a/lib/pm.h ++++ b/lib/pm.h +@@ -435,5 +435,12 @@ pm_parse_height(const char * const arg); + } + #endif +=20 ++void *malloc2(int, int); ++void *malloc3(int, int, int); ++#define overflow2(a,b) __overflow2(a,b) ++void __overflow2(int, int); ++void overflow3(int, int, int); ++void overflow_add(int, int); ++ +=20 + #endif +diff --git a/other/pnmcolormap.c b/other/pnmcolormap.c +index 57db432..7195295 100644 +--- a/other/pnmcolormap.c ++++ b/other/pnmcolormap.c +@@ -840,6 +840,7 @@ colormapToSquare(struct pam * const pamP, + pamP->width =3D intsqrt; + else=20 + pamP->width =3D intsqrt + 1; ++ overflow_add(intsqrt, 1); + } + { + unsigned int const intQuotient =3D colormap.size / pamP->width; +diff --git a/urt/Runput.c b/urt/Runput.c +index 3bc562a..645a376 100644 +--- a/urt/Runput.c ++++ b/urt/Runput.c +@@ -202,10 +202,11 @@ RunSetup(rle_hdr * the_hdr) + if ( the_hdr->background !=3D 0 ) + { + register int i; +- register rle_pixel *background =3D +- (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); +- register int *bg_color; +- /*=20 ++ register rle_pixel *background; ++ register int *bg_color; ++ ++ overflow_add(the_hdr->ncolors,1); ++ background =3D (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1= ) ); /* + * If even number of bg color bytes, put out one more to get to=20 + * 16 bit boundary. + */ +@@ -224,7 +225,7 @@ RunSetup(rle_hdr * the_hdr) + /* Big-endian machines are harder */ + register int i, nmap =3D (1 << the_hdr->cmaplen) * + the_hdr->ncmap; +- register char *h_cmap =3D (char *)malloc( nmap * 2 ); ++ register char *h_cmap =3D (char *)malloc2( nmap, 2 ); + if ( h_cmap =3D=3D NULL ) + { + fprintf( stderr, +diff --git a/urt/rle.h b/urt/rle.h +index 8d72cb9..ac65b94 100644 +--- a/urt/rle.h ++++ b/urt/rle.h +@@ -161,6 +161,17 @@ rle_hdr /* End of typedef. */ + */ + extern rle_hdr rle_dflt_hdr; +=20 ++/* ++ * Provided by pm library ++ */ ++ ++extern void overflow_add(int, int); ++#define overflow2(a,b) __overflow2(a,b) ++extern void __overflow2(int, int); ++extern void overflow3(int, int, int); ++extern void *malloc2(int, int); ++extern void *malloc3(int, int, int); ++extern void *realloc2(void *, int, int); +=20 + /* Declare RLE library routines. */ +=20 +diff --git a/urt/rle_addhist.c b/urt/rle_addhist.c +index b165175..e09ed94 100644 +--- a/urt/rle_addhist.c ++++ b/urt/rle_addhist.c +@@ -70,13 +70,18 @@ rle_addhist(char * argv[], + return; + =20 + length =3D 0; +- for (i =3D 0; argv[i]; ++i) ++ for (i =3D 0; argv[i]; ++i) { ++ overflow_add(length, strlen(argv[i])); ++ overflow_add(length+1, strlen(argv[i])); + length +=3D strlen(argv[i]) +1; /* length of each arg plus space.= */ ++ } +=20 + time(&temp); + timedate =3D ctime(&temp); + length +=3D strlen(timedate); /* length of date and time in ASCI= I. */ +- ++ overflow_add(strlen(padding), 4); ++ overflow_add(strlen(histoire), strlen(padding) + 4); ++ overflow_add(length, strlen(histoire) + strlen(padding) + 4); + length +=3D strlen(padding) + 3 + strlen(histoire) + 1; + /* length of padding, "on " and length of history name plus "=3D"*/ + if (in_hdr) /* if we are interested in the old comments... */ +@@ -84,8 +89,10 @@ rle_addhist(char * argv[], + else + old =3D NULL; + =20 +- if (old && *old) ++ if (old && *old) { ++ overflow_add(length, strlen(old)); + length +=3D strlen(old); /* add length if there. */ ++ } +=20 + ++length; /*Cater for the null. */ +=20 +diff --git a/urt/rle_getrow.c b/urt/rle_getrow.c +index bd7d1c8..bd05698 100644 +--- a/urt/rle_getrow.c ++++ b/urt/rle_getrow.c +@@ -168,6 +168,7 @@ rle_get_setup(rle_hdr * const the_hdr) { + char * cp; +=20 + VAXSHORT(comlen, infile); /* get comment length */ ++ overflow_add(comlen, 1); + evenlen =3D (comlen + 1) & ~1; /* make it even */ + if (evenlen) { + MALLOCARRAY(comment_buf, evenlen); +diff --git a/urt/rle_hdr.c b/urt/rle_hdr.c +index 1611324..7c9c010 100644 +--- a/urt/rle_hdr.c ++++ b/urt/rle_hdr.c +@@ -80,7 +80,10 @@ int img_num; + /* Fill in with copies of the strings. */ + if ( the_hdr->cmd !=3D pgmname ) + { +- char *tmp =3D (char *)malloc( strlen( pgmname ) + 1 ); ++ char *tmp; ++ ++ overflow_add(strlen(pgmname), 1); ++ tmp =3D malloc( strlen(pgmname) + 1 ); + RLE_CHECK_ALLOC( pgmname, tmp, 0 ); + strcpy( tmp, pgmname ); + the_hdr->cmd =3D tmp; +@@ -88,8 +91,10 @@ int img_num; +=20 + if ( the_hdr->file_name !=3D fname ) + { +- char *tmp =3D (char *)malloc( strlen( fname ) + 1 ); +- RLE_CHECK_ALLOC( pgmname, tmp, 0 ); ++ char *tmp; ++ overflow_add(strlen(fname), 1); ++ tmp =3D malloc( strlen( fname ) + 1 ); ++ RLE_CHECK_ALLOC( pgmname, tmp, 0 ); + strcpy( tmp, fname ); + the_hdr->file_name =3D tmp; + } +@@ -153,6 +158,7 @@ rle_hdr *from_hdr, *to_hdr; + if ( to_hdr->bg_color ) + { + int size =3D to_hdr->ncolors * sizeof(int); ++ overflow2(to_hdr->ncolors, sizeof(int)); + to_hdr->bg_color =3D (int *)malloc( size ); + RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->bg_color, "background color" ); + memcpy( to_hdr->bg_color, from_hdr->bg_color, size ); +@@ -161,7 +167,7 @@ rle_hdr *from_hdr, *to_hdr; + if ( to_hdr->cmap ) + { + int size =3D to_hdr->ncmap * (1 << to_hdr->cmaplen) * sizeof(rle_map); +- to_hdr->cmap =3D (rle_map *)malloc( size ); ++ to_hdr->cmap =3D (rle_map *)malloc3( to_hdr->ncmap, 1<cmap= len, sizeof(rle_map)); + RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->cmap, "color map" ); + memcpy( to_hdr->cmap, from_hdr->cmap, size ); + } +@@ -173,12 +179,17 @@ rle_hdr *from_hdr, *to_hdr; + { + int size =3D 0; + CONST_DECL char **cp; +- for ( cp=3Dto_hdr->comments; *cp; cp++ ) ++ for ( cp=3Dto_hdr->comments; *cp; cp++ ) ++ { ++ overflow_add(size, 1); + size++; /* Count the comments. */ ++ } + /* Check if there are really any comments. */ + if ( size ) + { ++ overflow_add(size, 1); + size++; /* Copy the NULL pointer, too. */ ++ overflow2(size, sizeof(char *)); + size *=3D sizeof(char *); + to_hdr->comments =3D (CONST_DECL char **)malloc( size ); + RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->comments, "comments" ); +diff --git a/urt/rle_open_f.c b/urt/rle_open_f.c +index ae8548b..c2ef37d 100644 +--- a/urt/rle_open_f.c ++++ b/urt/rle_open_f.c +@@ -163,65 +163,7 @@ dealWithSubprocess(const char * const file_name, + FILE ** const fpP, + bool * const noSubprocessP, + const char ** const errorP) { +- +-#ifdef NO_OPEN_PIPES + *noSubprocessP =3D TRUE; +-#else +- const char *cp; +- +- reapChildren(catchingChildrenP, pids); +- +- /* Real file, not stdin or stdout. If name ends in ".Z", +- * pipe from/to un/compress (depending on r/w mode). +- * =20 +- * If it starts with "|", popen that command. +- */ +- =20 +- cp =3D file_name + strlen(file_name) - 2; +- /* Pipe case. */ +- if (file_name[0] =3D=3D '|') { +- pid_t thepid; /* PID from my_popen */ +- +- *noSubprocessP =3D FALSE; +- +- *fpP =3D my_popen(file_name + 1, mode, &thepid); +- if (*fpP =3D=3D NULL) +- *errorP =3D "%s: can't invoke <<%s>> for %s: "; +- else { +- /* One more child to catch, eventually. */ +- if (*catchingChildrenP < MAX_CHILDREN) +- pids[(*catchingChildrenP)++] =3D thepid; +- } +- } else if (cp > file_name && *cp =3D=3D '.' && *(cp + 1) =3D=3D 'Z' ) { +- /* Compress case. */ +- pid_t thepid; /* PID from my_popen. */ +- const char * command; +- +- *noSubprocessP =3D FALSE; +- =20 +- if (*mode =3D=3D 'w') +- pm_asprintf(&command, "compress > %s", file_name); +- else if (*mode =3D=3D 'a') +- pm_asprintf(&command, "compress >> %s", file_name); +- else +- pm_asprintf(&command, "compress -d < %s", file_name); +- =20 +- *fpP =3D my_popen(command, mode, &thepid); +- +- if (*fpP =3D=3D NULL) +- *errorP =3D "%s: can't invoke 'compress' program, " +- "trying to open %s for %s"; +- else { +- /* One more child to catch, eventually. */ +- if (*catchingChildrenP < MAX_CHILDREN) +- pids[(*catchingChildrenP)++] =3D thepid; +- } +- pm_strfree(command); +- } else { +- *noSubprocessP =3D TRUE; +- *errorP =3D NULL; +- } +-#endif + } +=20 +=20 +diff --git a/urt/rle_putcom.c b/urt/rle_putcom.c +index ab2eb20..f6a6ff7 100644 +--- a/urt/rle_putcom.c ++++ b/urt/rle_putcom.c +@@ -98,12 +98,14 @@ rle_putcom(const char * const value, + const char * v; + const char ** old_comments; + int i; +- for (i =3D 2, cp =3D the_hdr->comments; *cp !=3D NULL; ++i, ++cp) ++ for (i =3D 2, cp =3D the_hdr->comments; *cp !=3D NULL; ++i, ++cp) { ++ overflow_add(i, 1); + if (match(value, *cp) !=3D NULL) { + v =3D *cp; + *cp =3D value; + return v; + } ++ } + /* Not found */ + /* Can't realloc because somebody else might be pointing to this + * comments block. Of course, if this were true, then the +diff --git a/urt/scanargs.c b/urt/scanargs.c +index f3af334..5e114bb 100644 +--- a/urt/scanargs.c ++++ b/urt/scanargs.c +@@ -62,9 +62,8 @@ typedef int *ptr; + /*=20 + * Storage allocation macros + */ +-#define NEW( type, cnt ) (type *) malloc( (cnt) * sizeof( type ) ) +-#define RENEW( type, ptr, cnt ) (type *) realloc( ptr, (cnt) * sizeof( type= ) ) +- ++#define NEW( type, cnt ) (type *) malloc2( (cnt) , sizeof( type ) ) ++#define RENEW( type, ptr, cnt ) (type *) realloc2( ptr, (cnt), sizeof( type= ) ) + static CONST_DECL char * prformat( CONST_DECL char *, int ); + static int isnum( CONST_DECL char *, int, int ); + static int _do_scanargs( int argc, char **argv, CONST_DECL char *format, + diff --git a/netpbm/patches/netpbm-security-scripts.patch b/netpbm/patches/ne= tpbm-security-scripts.patch new file mode 100644 index 000000000..0dfe84f43 --- /dev/null +++ b/netpbm/patches/netpbm-security-scripts.patch @@ -0,0 +1,369 @@ +diff --git a/converter/other/anytopnm b/converter/other/anytopnm +index acf8813..335312a 100755 +--- a/converter/other/anytopnm ++++ b/converter/other/anytopnm +@@ -511,10 +511,7 @@ else + inputFile=3D"-" + fi +=20 +-tempdir=3D"${TMPDIR-/tmp}/anytopnm.$$" +-mkdir -m 0700 $tempdir || \ +- { echo "Could not create temporary file. Exiting."; exit 1;} +-trap 'rm -rf $tempdir' 0 ++tempdir=3D$(mktemp -d -t anytopnm.XXXXXXXXXX) || exit 1 +=20 + # Take out all spaces + # Find the filename extension for last-ditch efforts later +@@ -537,12 +534,17 @@ typeDescription=3D`file "$file" | cut -d: -f2- | cut -= c2-` + determineType "$file" "$mimeType" "$typeDescription" "$fileExtension" +=20 + if [ "$filetype" =3D "unknown" ]; then +- echo "$progname: unknown file type. " \ +- "'file' says mime type is '$mimeType', " 1>&2 +- echo "type description is '$typeDescription'" 1>&2 ++ if [ -d "$tempdir" ] ; then ++ rm -rf "$tempdir" ++ fi ++ + exit 1 + fi +=20 + convertIt $file $filetype +=20 ++if [ -d "$tempdir" ] ; then ++ rm -rf "$tempdir" ++fi ++ + exit 0 +diff --git a/editor/pamstretch-gen b/editor/pamstretch-gen +index ba0e818..250fca0 100755 +--- a/editor/pamstretch-gen ++++ b/editor/pamstretch-gen +@@ -31,9 +31,7 @@ if [ "$1" =3D "" ]; then + exit 1 + fi +=20 +-tempdir=3D"${TMPDIR-/tmp}/pamstretch-gen.$$" +-mkdir -m 0700 $tempdir || \ +- { echo "Could not create temporary file. Exiting."; exit 1;} ++tempfile=3D$(mktemp /tmp/pnmig.XXXXXXXXXX) || exit 1 + trap 'rm -rf $tempdir' 0 1 3 15 +=20 + tempfile=3D$tempdir/pnmig +diff --git a/editor/pnmmargin b/editor/pnmmargin +index 0f57d1d..e0d3625 100755 +--- a/editor/pnmmargin ++++ b/editor/pnmmargin +@@ -11,11 +11,7 @@ + # documentation. This software is provided "as is" without express or + # implied warranty. +=20 +-tempdir=3D"${TMPDIR-/tmp}/pnmmargin.$$" +-mkdir -m 0700 $tempdir || \ +- { echo "Could not create temporary file. Exiting." 1>&2; exit 1;} +-trap 'rm -rf $tempdir' 0 1 3 15 +- ++tempdir=3D$(mktemp -d -t ppmmargin.XXXXXXX) || exit 1 + tmp1=3D$tempdir/pnmm1 + tmp2=3D$tempdir/pnmm2 + tmp3=3D$tempdir/pnmm3 +@@ -90,6 +86,7 @@ else + -white | -black ) + pnmpad $plainopt $color \ + -left=3D$size -right=3D$size -top=3D$size -bottom=3D$size $tmp1 ++ rm -rf "$tempdir" + exit + ;; + * ) +@@ -103,4 +100,4 @@ else + pnmcat -tb $plainopt $tmp3 $tmp4 $tmp3 + fi +=20 +- ++rm -rf "$tempdir" +diff --git a/editor/ppmfade b/editor/ppmfade +index 027fc79..8eb094f 100755 +--- a/editor/ppmfade ++++ b/editor/ppmfade +@@ -40,6 +40,7 @@ exec perl -w -x -S -- "$0" "$@" + # + ###########################################################################= ### + use strict; ++use File::Temp "tempdir"; +=20 + my $SPREAD =3D 1; + my $SHIFT =3D 2; +@@ -137,20 +138,26 @@ if ($first_file ne "undefined") { +=20 + print("Frames are " . $width . "W x " . $height . "H\n"); +=20 ++# ++# We create a tmp-directory right here ++# ++my $tmpdir =3D tempdir("ppmfade.XXXXXX", CLEANUP =3D> 1); ++ ++ + if ($first_file eq "undefined") { + print "Fading from black to "; +- system("ppmmake \\#000 $width $height >junk1$$.ppm"); ++ system("ppmmake \\#000 $width $height >$tmpdir/junk1$$.ppm"); + } else { + print "Fading from $first_file to "; +- system("cp", $first_file, "junk1$$.ppm"); ++ system("cp", $first_file, "$tmpdir/junk1$$.ppm"); + } +=20 + if ($last_file eq "undefined") { + print "black.\n"; +- system("ppmmake \\#000 $width $height >junk2$$.ppm"); ++ system("ppmmake \\#000 $width $height >$tmpdir/junk2$$.ppm"); + } else { + print "$last_file\n"; +- system("cp", $last_file, "junk2$$.ppm"); ++ system("cp", $last_file, "$tmpdir/junk2$$.ppm"); + } +=20 + # +@@ -158,14 +165,14 @@ if ($last_file eq "undefined") { + # +=20 + # Here's what our temporary files are: +-# junk1$$.ppm: The original (fade-from) image +-# junk2$$.ppm: The target (fade-from) image +-# junk3$$.ppm: The frame of the fade for the current iteration of the=20 +-# the for loop. +-# junk1a$$.ppm: If the fade involves a ppmmix sequence from one intermedi= ate +-# image to another, this is the first frame of that=20 +-# sequence. +-# junk2a$$.ppm: This is the last frame of the above-mentioned ppmmix sequ= ence ++# $tmpdir/junk1$$.ppm: The original (fade-from) image ++# $tmpdir/junk2$$.ppm: The target (fade-from) image ++# $tmpdir/junk3$$.ppm: The frame of the fade for the current iteration of= the=20 ++# the for loop. ++# $tmpdir/junk1a$$.ppm: If the fade involves a ppmmix sequence from one i= ntermediate ++# image to another, this is the first frame of that= =20 ++# sequence. ++# $tmpdir/junk2a$$.ppm: This is the last frame of the above-mentioned ppm= mix sequence +=20 + my $i; # Frame number + for ($i =3D 1; $i <=3D $nframes; $i++) { +@@ -173,147 +180,147 @@ for ($i =3D 1; $i <=3D $nframes; $i++) { + if ($mode eq $SPREAD) { + if ($i <=3D 10) { + my $n =3D $spline20[$i] * 100; +- system("ppmspread $n junk1$$.ppm >junk3$$.ppm"); ++ system("ppmspread $n $tmpdir/junk1$$.ppm >$tmpdir/junk3$$.ppm"); + } elsif ($i <=3D 20) { + my $n; + $n =3D $spline20[$i] * 100; +- system("ppmspread $n junk1$$.ppm >junk1a$$.ppm"); ++ system("ppmspread $n $tmpdir/junk1$$.ppm >$tmpdir/junk1a$$.ppm"= ); + $n =3D (1-$spline20[$i-10]) * 100; +- system("ppmspread $n junk2$$.ppm >junk2a$$.ppm"); ++ system("ppmspread $n $tmpdir/junk2$$.ppm >$tmpdir/junk2a$$.ppm"= ); + $n =3D $spline10[$i-10]; +- system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$t= mpdir/junk3$$.ppm"); + } else { + my $n =3D (1-$spline20[$i-10])*100; +- system("ppmspread $n junk2$$.ppm >junk3$$.ppm"); ++ system("ppmspread $n $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm"); + } + } elsif ($mode eq $SHIFT) { + if ($i <=3D 10) { + my $n =3D $spline20[$i] * 100; +- system("ppmshift $n junk1$$.ppm >junk3$$.ppm"); ++ system("ppmshift $n $tmpdir/junk1$$.ppm >$tmpdir/junk3$$.ppm"); + } elsif ($i <=3D 20) { + my $n; + $n =3D $spline20[$i] * 100; +- system("ppmshift $n junk1$$.ppm >junk1a$$.ppm"); ++ system("ppmshift $n $tmpdir/junk1$$.ppm >$tmpdir/junk1a$$.ppm"); + $n =3D (1-$spline20[$i-10])*100; +- system("ppmshift $n junk2$$.ppm >junk2a$$.ppm"); ++ system("ppmshift $n $tmpdir/junk2$$.ppm >$tmpdir/junk2a$$.ppm"); + $n =3D $spline10[$i-10]; +- system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$t= mpdir/junk3$$.ppm"); + } else { + my $n =3D (1-$spline20[$i-10]) * 100; +- system("ppmshift $n junk2$$.ppm >junk3$$.ppm"); ++ system("ppmshift $n $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm"); + } + } elsif ($mode eq $RELIEF) { + if ($i =3D=3D 1) { +- system("ppmrelief junk1$$.ppm >junk1r$$.ppm"); ++ system("ppmrelief $tmpdir/junk1$$.ppm >$tmpdir/junk1r$$.ppm"); + } + if ($i <=3D 10) { + my $n =3D $spline10[$i]; +- system("ppmmix $n junk1$$.ppm junk1r$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1r$$.ppm >$tm= pdir/junk3$$.ppm"); + } elsif ($i <=3D 20) { + my $n =3D $spline10[$i-10]; +- system("ppmmix $n junk1r$$.ppm junk2r$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1r$$.ppm $tmpdir/junk2r$$.ppm >$t= mpdir/junk3$$.ppm"); + } else { + my $n =3D $spline10[$i-20]; +- system("ppmmix $n junk2r$$.ppm junk2$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk2r$$.ppm $tmpdir/junk2$$.ppm >$tm= pdir/junk3$$.ppm"); + } + if ($i =3D=3D 10) { +- system("ppmrelief junk2$$.ppm >junk2r$$.ppm"); ++ system("ppmrelief $tmpdir/junk2$$.ppm >$tmpdir/junk2r$$.ppm"); + } + } elsif ($mode eq $OIL) { + if ($i =3D=3D 1) { +- system("ppmtopgm junk1$$.ppm | pgmoil >junko$$.ppm"); +- system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . +- ">junk1o$$.ppm"); ++ system("ppmtopgm $tmpdir/junk1$$.ppm | pgmoil >$tmpdir/junko$$.= ppm"); ++ system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpd= ir/junko$$.ppm " . ++ ">$tmpdir/junk1o$$.ppm"); + } + if ($i <=3D 10) { + my $n =3D $spline10[$i]; +- system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tm= pdir/junk3$$.ppm"); + } elsif ($i <=3D 20) { + my $n =3D $spline10[$i-10]; +- system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$t= mpdir/junk3$$.ppm"); + } else { + my $n =3D $spline10[$i-20]; +- system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tm= pdir/junk3$$.ppm"); + } + if ($i =3D=3D 10) { +- system("ppmtopgm junk2$$.ppm | pgmoil >junko$$.ppm"); +- system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . +- ">junk2o$$.ppm"); ++ system("ppmtopgm $tmpdir/junk2$$.ppm | pgmoil >$tmpdir/junko$$.= ppm"); ++ system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpd= ir/junko$$.ppm " . ++ ">$tmpdir/junk2o$$.ppm"); + } + } elsif ($mode eq $EDGE) { + if ($i =3D=3D 1) { +- system("ppmtopgm junk1$$.ppm | pgmedge >junko$$.ppm"); +- system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . +- ">junk1o$$.ppm"); ++ system("ppmtopgm $tmpdir/junk1$$.ppm | pgmedge >$tmpdir/junko$$= .ppm"); ++ system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpd= ir/junko$$.ppm " . ++ ">$tmpdir/junk1o$$.ppm"); + } + if ($i <=3D 10) { + my $n =3D $spline10[$i]; +- system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tm= pdir/junk3$$.ppm"); + } elsif ($i <=3D 20) { + my $n =3D $spline10[$i-10]; +- system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$t= mpdir/junk3$$.ppm"); + } else { + my $n =3D $spline10[$i-20]; +- system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tm= pdir/junk3$$.ppm"); + } + if ($i =3D=3D 10) { +- system("ppmtopgm junk2$$.ppm | pgmedge >junko$$.ppm"); +- system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . +- ">junk2o$$.ppm"); ++ system("ppmtopgm $tmpdir/junk2$$.ppm | pgmedge >$tmpdir/junko$$= .ppm"); ++ system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpd= ir/junko$$.ppm " . ++ ">$tmpdir/junk2o$$.ppm"); + }=20 + } elsif ($mode eq $BENTLEY) { + if ($i =3D=3D 1) { +- system("ppmtopgm junk1$$.ppm | pgmbentley >junko$$.ppm"); +- system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . +- ">junk1o$$.ppm"); ++ system("ppmtopgm $tmpdir/junk1$$.ppm | pgmbentley >$tmpdir/junk= o$$.ppm"); ++ system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpd= ir/junko$$.ppm " . ++ ">$tmpdir/junk1o$$.ppm"); + } + if ($i <=3D 10) { + my $n =3D $spline10[$i]; +- system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tm= pdir/junk3$$.ppm"); + } elsif ($i <=3D 20) { + my $n =3D $spline10[$i-10]; +- system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$t= mpdir/junk3$$.ppm"); + } else { + my $n =3D $spline10[$i-20]; +- system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tm= pdir/junk3$$.ppm"); + } + if ($i =3D=3D 10) { +- system("ppmtopgm junk2$$.ppm | pgmbentley >junko$$.ppm"); +- system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " . +- ">junk2o$$.ppm"); ++ system("ppmtopgm $tmpdir/junk2$$.ppm | pgmbentley >$tmpdir/junk= o$$.ppm"); ++ system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpd= ir/junko$$.ppm " . ++ ">$tmpdir/junk2o$$.ppm"); + } + } elsif ($mode eq $BLOCK) { + if ($i <=3D 10) { + my $n =3D 1 - 1.9*$spline20[$i]; +- system("pamscale $n junk1$$.ppm | " . +- "pamscale -width $width -height $height >junk3$$.ppm"); ++ system("pamscale $n $tmpdir/junk1$$.ppm | " . ++ "pamscale -width $width -height $height >$tmpdir/junk3$$= .ppm"); + } elsif ($i <=3D 20) { + my $n =3D $spline10[$i-10]; +- system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm"); ++ system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$t= mpdir/junk3$$.ppm"); + } else { + my $n =3D 1 - 1.9*$spline20[31-$i]; +- system("pamscale $n junk2$$.ppm | " . +- "pamscale -width $width -height $height >junk3$$.ppm"); ++ system("pamscale $n $tmpdir/junk2$$.ppm | " . ++ "pamscale -width $width -height $height >$tmpdir/junk3$$= .ppm"); + } + if ($i =3D=3D 10) { +- system("cp", "junk3$$.ppm", "junk1a$$.ppm"); +- system("pamscale $n junk2$$.ppm | " . +- "pamscale -width $width -height $height >junk2a$$.ppm"); ++ system("cp", "$tmpdir/junk3$$.ppm", "$tmpdir/junk1a$$.ppm"); ++ system("pamscale $n $tmpdir/junk2$$.ppm | " . ++ "pamscale -width $width -height $height >$tmpdir/junk2a$= $.ppm"); + } =20 + } elsif ($mode eq $MIX) { + my $fade_factor =3D sqrt(1/($nframes-$i+1)); +- system("ppmmix $fade_factor junk1$$.ppm junk2$$.ppm >junk3$$.ppm"); ++ system("ppmmix $fade_factor $tmpdir/junk1$$.ppm $tmpdir/junk2$$.ppm= >$tmpdir/junk3$$.ppm"); + } else { + print("Internal error: impossible mode value '$mode'\n"); + } +=20 + my $outfile =3D sprintf("%s.%04d.ppm", $base_name, $i); +- system("cp", "junk3$$.ppm", $outfile); ++ system("cp", "$tmpdir/junk3$$.ppm", $outfile); + } +=20 + # + # Clean up shop. + # +-system("rm junk*$$.ppm"); ++system("rm $tmpdir/junk*$$.ppm"); +=20 + exit(0); +diff --git a/editor/ppmshadow b/editor/ppmshadow +index 62cdf8b..72e1b22 100755 +--- a/editor/ppmshadow ++++ b/editor/ppmshadow +@@ -97,9 +97,10 @@ sub makeConvolutionKernel($$) { +=20 +=20 + my $tmpdir =3D $ENV{TMPDIR} || "/tmp"; +-my $ourtmp =3D "$tmpdir/ppmshadow$$"; +-mkdir($ourtmp, 0777) or +- die("Unable to create directory for temporary files '$ourtmp"); ++my $ourtmp; chomp($ourtmp =3D `mktemp -d -t PPMshadow.XXXXXX`); ++if ($? >> 8) { ++ die "Can't create directory for temporary files"; ++} +=20 + # Process command line options +=20 + --=20 2.30.2 --===============6676574825940069219==--