From 37f38cafb6719d3bde8c487a597400a81d733aba Mon Sep 17 00:00:00 2001 From: giraffedata Date: Fri, 29 Aug 2008 19:47:32 +0000 Subject: Release 10.35.50 git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@718 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- analyzer/pgmhist.c | 8 ++++++++ doc/HISTORY | 15 +++++++++++++++ editor/pamcomp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ editor/pamcut.c | 12 +++++++++++- lib/libpnm3.c | 13 ++++++++----- 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/analyzer/pgmhist.c b/analyzer/pgmhist.c index 8f4e512e..126fe693 100644 --- a/analyzer/pgmhist.c +++ b/analyzer/pgmhist.c @@ -10,6 +10,8 @@ ** implied warranty. */ +#include + #include "pgm.h" #include "mallocvar.h" @@ -42,6 +44,12 @@ main( argc, argv ) pm_usage( usage ); pgm_readpgminit( ifp, &cols, &rows, &maxval, &format ); + + if (UINT_MAX / cols < rows) + pm_error("Too many pixels (%u x %u) in image. " + "Maximum computable is %u", + cols, rows, UINT_MAX); + grayrow = pgm_allocrow( cols ); /* Build histogram. */ diff --git a/doc/HISTORY b/doc/HISTORY index c23298fc..16fc4535 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -4,6 +4,21 @@ Netpbm. CHANGE HISTORY -------------- +08.08.29 BJH Release 10.35.50 + + pnm_backgroundxel(), pnm_backgroundxelrow() (affects + pnmrotate, pnmshear, pnmcrop, pnmcat: correctly average + corner colors to determine background (fill) color. + + pgmhist: arbitrary output when total pixels doesn't fit in an + integer. + + pamcomp: fix bug: arbitrary output when combined number of rows + doesn't fit in an integer. + + pamcut: don't crash when left > right or top > bottom with + -pad. Thanks Prophet of the Way . + 08.08.13 BJH Release 10.35.49 pamcut: don't crash when cutting a region entirely to the diff --git a/editor/pamcomp.c b/editor/pamcomp.c index f7346483..fd3147a2 100644 --- a/editor/pamcomp.c +++ b/editor/pamcomp.c @@ -305,6 +305,44 @@ warnOutOfFrame( int const originLeft, +static void +validateComputableHeight(int const originTop, + int const overRows) { + + if (originTop < 0) { + if (originTop < -INT_MAX) + pm_error("Overlay starts too far above the underlay image to be " + "computable. Overlay can be at most %d rows above " + "the underlay.", INT_MAX); + } else { + if (INT_MAX - originTop <= overRows) + pm_error("Too many total rows involved to be computable. " + "You must have a shorter overlay image or compose it " + "higher on the underlay image."); + } +} + + + +static void +validateComputableHeight(int const originTop, + int const overRows) { + + if (originTop < 0) { + if (originTop < -INT_MAX) + pm_error("Overlay starts too far above the underlay image to be " + "computable. Overlay can be at most %d rows above " + "the underlay.", INT_MAX); + } else { + if (INT_MAX - originTop <= overRows) + pm_error("Too many total rows involved to be computable. " + "You must have a shorter overlay image or compose it " + "higher on the underlay image."); + } +} + + + static void computeOverlayPosition(int const underCols, int const underRows, @@ -340,6 +378,10 @@ computeOverlayPosition(int const underCols, *originLeftP = xalign + cmdline.xoff; *originTopP = yalign + cmdline.yoff; + validateComputableHeight(*originTopP, overRows); + + validateComputableHeight(*originTopP, overRows); + warnOutOfFrame(*originLeftP, *originTopP, overCols, overRows, underCols, underRows); } diff --git a/editor/pamcut.c b/editor/pamcut.c index 7d95fa0a..c5d53f44 100644 --- a/editor/pamcut.c +++ b/editor/pamcut.c @@ -504,7 +504,17 @@ cutOneImage(FILE * const ifP, if (!cmdline.pad) rejectOutOfBounds(inpam.width, inpam.height, leftcol, rightcol, toprow, bottomrow); - + else { + if (cmdline.left > cmdline.right) + pm_error("You have specified a left edge (%d) that is to the right\n" + "of the right edge you specified (%d)", + cmdline.left, cmdline.right); + + if (cmdline.top > cmdline.bottom) + pm_error("You have specified a top edge (%d) that is below\n" + "the bottom edge you specified (%d)", + cmdline.top, cmdline.bottom); + } if (cmdline.verbose) { pm_message("Image goes from Row 0, Column 0 through Row %d, Column %d", inpam.height-1, inpam.width-1); diff --git a/lib/libpnm3.c b/lib/libpnm3.c index f10a7fca..99d35dc0 100644 --- a/lib/libpnm3.c +++ b/lib/libpnm3.c @@ -65,9 +65,9 @@ pnm_backgroundxel( xels, cols, rows, maxval, format ) { case PPM_TYPE: PPM_ASSIGN( bgxel, - PPM_GETR(ul) + PPM_GETR(ur) + PPM_GETR(ll) + PPM_GETR(lr) / 4, - PPM_GETG(ul) + PPM_GETG(ur) + PPM_GETG(ll) + PPM_GETG(lr) / 4, - PPM_GETB(ul) + PPM_GETB(ur) + PPM_GETB(ll) + PPM_GETB(lr) / 4 ); + (PPM_GETR(ul) + PPM_GETR(ur) + PPM_GETR(ll) + PPM_GETR(lr)) / 4, + (PPM_GETG(ul) + PPM_GETG(ur) + PPM_GETG(ll) + PPM_GETG(lr)) / 4, + (PPM_GETB(ul) + PPM_GETB(ur) + PPM_GETB(ll) + PPM_GETB(lr)) / 4 ); break; case PGM_TYPE: @@ -120,8 +120,11 @@ pnm_backgroundxelrow( xelrow, cols, maxval, format ) switch ( PNM_FORMAT_TYPE(format) ) { case PPM_TYPE: - PPM_ASSIGN( bgxel, PPM_GETR(l) + PPM_GETR(r) / 2, - PPM_GETG(l) + PPM_GETG(r) / 2, PPM_GETB(l) + PPM_GETB(r) / 2 ); + PPM_ASSIGN(bgxel, + (PPM_GETR(l) + PPM_GETR(r)) / 2, + (PPM_GETG(l) + PPM_GETG(r)) / 2, + (PPM_GETB(l) + PPM_GETB(r)) / 2 + ); break; case PGM_TYPE: -- cgit 1.4.1