fix int overflow in shrinkv

This commit is contained in:
John Cupitt 2019-08-03 03:31:54 +01:00
parent cfe0857ae1
commit 3c8a9815ba
1 changed files with 9 additions and 8 deletions

View File

@ -199,12 +199,13 @@ vips_shrinkv_add_line( VipsShrinkv *shrink, VipsShrinkvSequence *seq,
/* Integer average. /* Integer average.
*/ */
#define IAVG( TYPE ) { \ #define IAVG( TYPE, BTYPE ) { \
int * restrict sum = (int *) seq->sum; \ int * restrict sum = (int *) seq->sum; \
TYPE * restrict q = (TYPE *) out; \ TYPE * restrict q = (TYPE *) out; \
\ \
for( x = 0; x < sz; x++ ) \ for( x = 0; x < sz; x++ ) \
q[x] = (sum[x] + shrink->vshrink / 2) / shrink->vshrink; \ q[x] = ((BTYPE) sum[x] + shrink->vshrink / 2) / \
shrink->vshrink; \
} }
/* Float average. /* Float average.
@ -234,17 +235,17 @@ vips_shrinkv_write_line( VipsShrinkv *shrink, VipsShrinkvSequence *seq,
VipsPel *out = VIPS_REGION_ADDR( or, left, top ); VipsPel *out = VIPS_REGION_ADDR( or, left, top );
switch( resample->in->BandFmt ) { switch( resample->in->BandFmt ) {
case VIPS_FORMAT_UCHAR: case VIPS_FORMAT_UCHAR:
IAVG( unsigned char ); break; IAVG( unsigned char, int ); break;
case VIPS_FORMAT_CHAR: case VIPS_FORMAT_CHAR:
IAVG( char ); break; IAVG( char, int ); break;
case VIPS_FORMAT_USHORT: case VIPS_FORMAT_USHORT:
IAVG( unsigned short ); break; IAVG( unsigned short, int ); break;
case VIPS_FORMAT_SHORT: case VIPS_FORMAT_SHORT:
IAVG( short ); break; IAVG( short, int ); break;
case VIPS_FORMAT_UINT: case VIPS_FORMAT_UINT:
IAVG( unsigned int ); break; IAVG( unsigned int, int ); break;
case VIPS_FORMAT_INT: case VIPS_FORMAT_INT:
IAVG( int ); break; IAVG( int, gint64 ); break;
case VIPS_FORMAT_FLOAT: case VIPS_FORMAT_FLOAT:
FAVG( float ); break; FAVG( float ); break;
case VIPS_FORMAT_DOUBLE: case VIPS_FORMAT_DOUBLE: