From c34adb82dc8d0ec0d5a66e9a5af2db18ea825c1b Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 29 Sep 2018 02:55:26 +0000 Subject: Release 10.73.21 git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@3347 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/pstopnm.c | 24 ++++++++++++++++++------ doc/HISTORY | 15 +++++++++++++++ editor/pbmmask.c | 5 +++++ lib/libpbmfont.c | 38 ++++++++++++++++++++++++++++++++++---- version.mk | 2 +- 5 files changed, 73 insertions(+), 11 deletions(-) diff --git a/converter/other/pstopnm.c b/converter/other/pstopnm.c index b253442f..eb4d9d46 100644 --- a/converter/other/pstopnm.c +++ b/converter/other/pstopnm.c @@ -308,10 +308,14 @@ computeSizeResBlind(unsigned int const xmax, unsigned int const imageHeight, bool const nocrop, struct Dimensions * const imageDimP) { - - imageDimP->xres = imageDimP->yres = MIN(xmax * 72 / imageWidth, - ymax * 72 / imageHeight); - + + if (imageWidth == 0 || imageHeight == 0) { + imageDimP->xres = imageDimP->yres = 72; + } else { + imageDimP->xres = imageDimP->yres = MIN(xmax * 72 / imageWidth, + ymax * 72 / imageHeight); + } + if (nocrop) { imageDimP->xsize = xmax; imageDimP->ysize = ymax; @@ -361,10 +365,13 @@ computeSizeRes(struct CmdlineInfo const cmdline, imageDimP->xres = imageDimP->yres = cmdline.dpi; imageDimP->xsize = ROUNDU(cmdline.dpi * sx / 72.0); imageDimP->ysize = ROUNDU(cmdline.dpi * sy / 72.0); - } else if (cmdline.xsize || cmdline.ysize) + } else if (cmdline.xsize || cmdline.ysize) { + if (sx == 0 || sy == 0) + pm_error("Input image is zero size; we cannot satisfy your " + "produce your requested output dimensions"); computeSizeResFromSizeSpec(cmdline.xsize, cmdline.ysize, sx, sy, imageDimP); - else + } else computeSizeResBlind(cmdline.xmax, cmdline.ymax, sx, sy, cmdline.nocrop, imageDimP); @@ -1030,6 +1037,11 @@ main(int argc, char ** argv) { borderedBox = addBorders(extractBox, cmdline.xborder, cmdline.yborder); computeSizeRes(cmdline, borderedBox, &imageDim); + + if (imageDim.xres == 0) + imageDim.xres = 1; + if (imageDim.yres == 0) + imageDim.yres = 1; outfileArg = computeOutfileArg(cmdline); diff --git a/doc/HISTORY b/doc/HISTORY index 87f815b8..3f69d629 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -4,6 +4,21 @@ Netpbm. CHANGE HISTORY -------------- +18.09.29 BJH Release 10.73.21 + + pstopnm: Fix divide-by-zero crash when Postscript input says + the image has zero size. + + pstopnm: Fix divide-by-zero crash when computed resolution + rounds down to zero dots per inch. + + pbmtext; libnetpbm BDF font processing: fix invalid memory + reference when BDF font file has invalid syntax. Broken + in primordial Netpbm, ca 1993. + + pbmmask: Fix invalid memory reference with zero-dimension + input image. Broken in primordial Netpbm, ca 1989. + 18.06.27 BJH Release 10.73.20 Pngtopam: Fix bogus warning of non-square pixels when image does diff --git a/editor/pbmmask.c b/editor/pbmmask.c index 21ada6b9..25c71226 100644 --- a/editor/pbmmask.c +++ b/editor/pbmmask.c @@ -143,6 +143,11 @@ main(int argc, char * argv[]) { pm_usage( usage ); bits = pbm_readpbm( ifp, &cols, &rows ); + + if (cols == 0 || rows == 0) + pm_error("Image contains no pixels, so there is no such thing " + "as background and foreground"); + pm_close( ifp ); mask = pbm_allocarray( cols, rows ); diff --git a/lib/libpbmfont.c b/lib/libpbmfont.c index 7a3a236f..d3551e78 100644 --- a/lib/libpbmfont.c +++ b/lib/libpbmfont.c @@ -1374,6 +1374,8 @@ interpEncoding(const char ** const arg, bool badCodepoint; unsigned int codepoint; + if (!arg[1]) + pm_error("Invalid ENCODING statement - no arguments"); if (atoi(arg[1]) >= 0) { codepoint = atoi(arg[1]); gotCodepoint = true; @@ -1418,10 +1420,14 @@ processChars(readline * const readlineP, just after the CHARS line. Read the rest of the block and apply its contents to *fontP. -----------------------------------------------------------------------------*/ - unsigned int const nCharacters = atoi(readlineP->arg[1]); - + unsigned int nCharacters; unsigned int nCharsDone; + if (!readlineP->arg[1]) + pm_error("Invalid CHARS line - no arguments"); + + nCharacters = atoi(readlineP->arg[1]); + nCharsDone = 0; while (nCharsDone < nCharacters) { @@ -1435,6 +1441,8 @@ processChars(readline * const readlineP, /* ignore */ } else if (!streq(readlineP->arg[0], "STARTCHAR")) pm_error("no STARTCHAR after CHARS in BDF font file"); + else if (!readlineP->arg[1]) + pm_error("Invalid STARTCHAR - no arguments"); else { const char * const charName = readlineP->arg[1]; @@ -1458,12 +1466,22 @@ processChars(readline * const readlineP, readExpectedStatement(readlineP, "SWIDTH"); readExpectedStatement(readlineP, "DWIDTH"); + if (!readlineP->arg[1]) + pm_error("Invalid DWIDTH statement - no arguments"); glyphP->xadd = atoi(readlineP->arg[1]); readExpectedStatement(readlineP, "BBX"); + if (!readlineP->arg[1]) + pm_error("Invalid BBX statement - no arguments"); glyphP->width = atoi(readlineP->arg[1]); + if (!readlineP->arg[2]) + pm_error("Invalid BBX statement - only 1 argument"); glyphP->height = atoi(readlineP->arg[2]); + if (!readlineP->arg[3]) + pm_error("Invalid BBX statement - only 2 arguments"); glyphP->x = atoi(readlineP->arg[3]); + if (!readlineP->arg[4]) + pm_error("Invalid BBX statement - only 3 arguments"); glyphP->y = atoi(readlineP->arg[4]); createBmap(glyphP->width, glyphP->height, readlineP, charName, @@ -1502,9 +1520,13 @@ processBdfFontLine(readline * const readlineP, /* ignore */ } else if (streq(readlineP->arg[0], "STARTPROPERTIES")) { /* Read off the properties and ignore them all */ - unsigned int const propCount = atoi(readlineP->arg[1]); - + unsigned int propCount; unsigned int i; + + if (!readlineP->arg[1]) + pm_error("Invalid STARTPROPERTIES statement - no arguments"); + propCount = atoi(readlineP->arg[1]); + for (i = 0; i < propCount; ++i) { bool eof; readline_read(readlineP, &eof); @@ -1512,9 +1534,17 @@ processBdfFontLine(readline * const readlineP, pm_error("End of file after STARTPROPERTIES in BDF font file"); } } else if (streq(readlineP->arg[0], "FONTBOUNDINGBOX")) { + if (!readlineP->arg[1]) + pm_error("Invalid FONTBOUNDINGBOX statement - no arguments"); fontP->maxwidth = atoi(readlineP->arg[1]); + if (!readlineP->arg[2]) + pm_error("Invalid FONTBOUNDINGBOX statement - only 1 argument"); fontP->maxheight = atoi(readlineP->arg[2]); + if (!readlineP->arg[3]) + pm_error("Invalid FONTBOUNDINGBOX statement - only 2 arguments"); fontP->x = atoi(readlineP->arg[3]); + if (!readlineP->arg[4]) + pm_error("Invalid FONTBOUNDINGBOX statement - only 3 arguments"); fontP->y = atoi(readlineP->arg[4]); } else if (streq(readlineP->arg[0], "ENDFONT")) { *endOfFontP = true; diff --git a/version.mk b/version.mk index d43b963a..10fc2155 100644 --- a/version.mk +++ b/version.mk @@ -1,3 +1,3 @@ NETPBM_MAJOR_RELEASE = 10 NETPBM_MINOR_RELEASE = 73 -NETPBM_POINT_RELEASE = 20 +NETPBM_POINT_RELEASE = 21 -- cgit 1.4.1