diff --git a/ChangeLog b/ChangeLog index 3fd70ee9..a359be0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ - remove stray trailing comma from iiif3 dirnames [whalehub] - fix TTF load [chregu] - revise GIF save alpha threshold [jfcalvo] +- raise libpng pixel size limit from 1m to 10m pixels [jskrzypek] 21/11/21 started 8.12.1 - fix insert [chregu] diff --git a/libvips/foreign/vipspng.c b/libvips/foreign/vipspng.c index 19bc4ab0..2c2999d8 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -83,6 +83,8 @@ * - read out background, if we can * 29/8/21 joshuamsager * - add "unlimited" flag to png load + * 13/1/22 + * - raise libpng pixel size limit to VIPS_MAX_COORD */ /* @@ -304,6 +306,10 @@ read_new( VipsSource *source, VipsImage *out, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE ); #endif /*FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION*/ + /* libpng has a default soft limit of 1m pixels per axis. + */ + png_set_user_limits( read->pPng, VIPS_MAX_COORD, VIPS_MAX_COORD ); + if( vips_source_rewind( source ) ) return( NULL ); png_set_read_fn( read->pPng, read, vips_png_read_source ); @@ -1046,7 +1052,8 @@ write_vips( Write *write, if( vips_image_pio_input( in ) ) return( -1 ); } - if( compress < 0 || compress > 9 ) { + if( compress < 0 || + compress > 9 ) { vips_error( "vips2png", "%s", _( "compress should be in [0,9]" ) ); return( -1 ); @@ -1085,6 +1092,10 @@ write_vips( Write *write, interlace_type = interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE; + /* libpng has a default soft limit of 1m pixels per axis. + */ + png_set_user_limits( write->pPng, VIPS_MAX_COORD, VIPS_MAX_COORD ); + png_set_IHDR( write->pPng, write->pInfo, in->Xsize, in->Ysize, bitdepth, color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT );