From 1504ca7cdc11ddf9e0f5a6e7315761c0fe6aa166 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 3 Dec 2015 12:14:39 +0000 Subject: [PATCH] have a more formal max image dimension we now have VIPS_MAX_COORD for maximum image dimension, set to 10m pixels ... we could go up to 2bn, but 10m seems a reasonable max, at least for now see https://github.com/jcupitt/libvips/issues/355 --- libvips/arithmetic/max.c | 4 ++-- libvips/arithmetic/min.c | 4 ++-- libvips/conversion/copy.c | 10 +++++----- libvips/conversion/wrap.c | 4 ++-- libvips/create/black.c | 6 +++--- libvips/create/fractsurf.c | 4 ++-- libvips/create/gaussnoise.c | 4 ++-- libvips/create/point.c | 4 ++-- libvips/create/text.c | 2 +- libvips/create/xyz.c | 10 +++++----- libvips/foreign/rawload.c | 6 +++--- libvips/foreign/tiff2vips.c | 4 ++-- libvips/histogram/hist_local.c | 4 ++-- libvips/include/vips/image.h | 9 +++++++++ libvips/iofuncs/image.c | 10 +++++----- 15 files changed, 47 insertions(+), 38 deletions(-) diff --git a/libvips/arithmetic/max.c b/libvips/arithmetic/max.c index c40a2f1b..c189384ae 100644 --- a/libvips/arithmetic/max.c +++ b/libvips/arithmetic/max.c @@ -434,14 +434,14 @@ vips_max_class_init( VipsMaxClass *class ) _( "Horizontal position of maximum" ), VIPS_ARGUMENT_OPTIONAL_OUTPUT, G_STRUCT_OFFSET( VipsMax, x ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "y", 3, _( "y" ), _( "Vertical position of maximum" ), VIPS_ARGUMENT_OPTIONAL_OUTPUT, G_STRUCT_OFFSET( VipsMax, y ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "size", 4, _( "Size" ), diff --git a/libvips/arithmetic/min.c b/libvips/arithmetic/min.c index cde84cae..6cadf068 100644 --- a/libvips/arithmetic/min.c +++ b/libvips/arithmetic/min.c @@ -437,14 +437,14 @@ vips_min_class_init( VipsMinClass *class ) _( "Horizontal position of minimum" ), VIPS_ARGUMENT_OPTIONAL_OUTPUT, G_STRUCT_OFFSET( VipsMin, x ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "y", 3, _( "y" ), _( "Vertical position of minimum" ), VIPS_ARGUMENT_OPTIONAL_OUTPUT, G_STRUCT_OFFSET( VipsMin, y ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "size", 4, _( "Size" ), diff --git a/libvips/conversion/copy.c b/libvips/conversion/copy.c index 4a45dea9..b02359bc 100644 --- a/libvips/conversion/copy.c +++ b/libvips/conversion/copy.c @@ -285,21 +285,21 @@ vips_copy_class_init( VipsCopyClass *class ) _( "Image width in pixels" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsCopy, width ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "height", 4, _( "Height" ), _( "Image height in pixels" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsCopy, height ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "bands", 5, _( "Bands" ), _( "Number of bands in image" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsCopy, bands ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_ENUM( class, "format", 6, _( "Format" ), @@ -341,14 +341,14 @@ vips_copy_class_init( VipsCopyClass *class ) _( "Horizontal offset of origin" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsCopy, xoffset ), - -1000000, 1000000, 0 ); + -VIPS_MAX_COORD, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "yoffset", 12, _( "Yoffset" ), _( "Vertical offset of origin" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsCopy, yoffset ), - -1000000, 1000000, 0 ); + -VIPS_MAX_COORD, VIPS_MAX_COORD, 0 ); } static void diff --git a/libvips/conversion/wrap.c b/libvips/conversion/wrap.c index c85ed6c6..7c02f208 100644 --- a/libvips/conversion/wrap.c +++ b/libvips/conversion/wrap.c @@ -126,14 +126,14 @@ vips_wrap_class_init( VipsWrapClass *class ) _( "Left edge of input in output" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsWrap, x ), - -1000000, 1000000, 0 ); + -VIPS_MAX_COORD, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "y", 4, _( "y" ), _( "Top edge of input in output" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsWrap, y ), - -1000000, 1000000, 0 ); + -VIPS_MAX_COORD, VIPS_MAX_COORD, 0 ); } diff --git a/libvips/create/black.c b/libvips/create/black.c index 83ac451c..dfa2ede2 100644 --- a/libvips/create/black.c +++ b/libvips/create/black.c @@ -130,21 +130,21 @@ vips_black_class_init( VipsBlackClass *class ) _( "Image width in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsBlack, width ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "height", 5, _( "Height" ), _( "Image height in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsBlack, height ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "bands", 6, _( "Bands" ), _( "Number of bands in image" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsBlack, bands ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); } static void diff --git a/libvips/create/fractsurf.c b/libvips/create/fractsurf.c index 6d571176..e6c07ef8 100644 --- a/libvips/create/fractsurf.c +++ b/libvips/create/fractsurf.c @@ -103,14 +103,14 @@ vips_fractsurf_class_init( VipsFractsurfClass *class ) _( "Image width in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsFractsurf, width ), - 1, 1000000, 64 ); + 1, VIPS_MAX_COORD, 64 ); VIPS_ARG_INT( class, "height", 5, _( "Height" ), _( "Image height in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsFractsurf, height ), - 1, 1000000, 64 ); + 1, VIPS_MAX_COORD, 64 ); VIPS_ARG_DOUBLE( class, "fractal_dimension", 8, _( "Fractal dimension" ), diff --git a/libvips/create/gaussnoise.c b/libvips/create/gaussnoise.c index 09145a68..5fee656e 100644 --- a/libvips/create/gaussnoise.c +++ b/libvips/create/gaussnoise.c @@ -154,14 +154,14 @@ vips_gaussnoise_class_init( VipsGaussnoiseClass *class ) _( "Image width in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsGaussnoise, width ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "height", 5, _( "Height" ), _( "Image height in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsGaussnoise, height ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_DOUBLE( class, "mean", 6, _( "Mean" ), diff --git a/libvips/create/point.c b/libvips/create/point.c index 5eff84ac..06e14229 100644 --- a/libvips/create/point.c +++ b/libvips/create/point.c @@ -144,14 +144,14 @@ vips_point_class_init( VipsPointClass *class ) _( "Image width in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsPoint, width ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "height", 3, _( "Height" ), _( "Image height in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsPoint, height ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_BOOL( class, "uchar", 4, _( "Uchar" ), diff --git a/libvips/create/text.c b/libvips/create/text.c index 01262927..f7ea3122 100644 --- a/libvips/create/text.c +++ b/libvips/create/text.c @@ -298,7 +298,7 @@ vips_text_class_init( VipsTextClass *class ) _( "Maximum image width in pixels" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsText, width ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_ENUM( class, "align", 7, _( "Align" ), diff --git a/libvips/create/xyz.c b/libvips/create/xyz.c index d4a9940e..852de729 100644 --- a/libvips/create/xyz.c +++ b/libvips/create/xyz.c @@ -194,35 +194,35 @@ vips_xyz_class_init( VipsXyzClass *class ) _( "Image width in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsXyz, width ), - 1, 1000000, 64 ); + 1, VIPS_MAX_COORD, 64 ); VIPS_ARG_INT( class, "height", 5, _( "Height" ), _( "Image height in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsXyz, height ), - 1, 1000000, 64 ); + 1, VIPS_MAX_COORD, 64 ); VIPS_ARG_INT( class, "csize", 6, _( "csize" ), _( "Size of third dimension" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsXyz, csize ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "dsize", 7, _( "dsize" ), _( "Size of fourth dimension" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsXyz, dsize ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "esize", 8, _( "esize" ), _( "Size of fifth dimension" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsXyz, esize ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); } diff --git a/libvips/foreign/rawload.c b/libvips/foreign/rawload.c index 39f89278..98cf4ec5 100644 --- a/libvips/foreign/rawload.c +++ b/libvips/foreign/rawload.c @@ -124,21 +124,21 @@ vips_foreign_load_raw_class_init( VipsForeignLoadRawClass *class ) _( "Image width in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsForeignLoadRaw, width ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "height", 11, _( "Height" ), _( "Image height in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsForeignLoadRaw, height ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "bands", 12, _( "Bands" ), _( "Number of bands in image" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsForeignLoadRaw, bands ), - 0, 1000000, 0 ); + 0, VIPS_MAX_COORD, 0 ); VIPS_ARG_UINT64( class, "offset", 13, _( "Size of header" ), diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index fb620d87..e1fa9609 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -1126,9 +1126,9 @@ parse_header( ReadTiff *rtiff, VipsImage *out ) */ if( width <= 0 || - width > 10000000 || + width > VIPS_MAX_COORD || height <= 0 || - height > 10000000 ) { + height > VIPS_MAX_COORD ) { vips_error( "tiff2vips", "%s", _( "width/height out of range" ) ); return( -1 ); diff --git a/libvips/histogram/hist_local.c b/libvips/histogram/hist_local.c index 15c518f7..59472ea2 100644 --- a/libvips/histogram/hist_local.c +++ b/libvips/histogram/hist_local.c @@ -313,14 +313,14 @@ vips_hist_local_class_init( VipsHistLocalClass *class ) _( "Window width in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsHistLocal, width ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "height", 5, _( "Height" ), _( "Window height in pixels" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsHistLocal, height ), - 1, 1000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); } static void diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index 2a362d9a..1c354757 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -47,6 +47,15 @@ extern "C" { #define VIPS_MAGIC_INTEL (0xb6a6f208U) #define VIPS_MAGIC_SPARC (0x08f2a6b6U) +/* We have a maximum value for a coordinate at various points for sanity + * checking. For example, vips_black() has a max with and height. We use int + * for width/height so we could go up to 2bn, but it's good to have a lower + * value set so we can see crazy numbers early. + * + * This was 1m for a while, but someone found a use for a 4m wide image. + */ +#define VIPS_MAX_COORD (10000000) + typedef enum { VIPS_DEMAND_STYLE_ERROR = -1, VIPS_DEMAND_STYLE_SMALLTILE, diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index c1ff191d..d9608f6f 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -1119,21 +1119,21 @@ vips_image_class_init( VipsImageClass *class ) _( "Image width in pixels" ), VIPS_ARGUMENT_SET_ALWAYS, G_STRUCT_OFFSET( VipsImage, Xsize ), - 1, 1000000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "height", 3, _( "Height" ), _( "Image height in pixels" ), VIPS_ARGUMENT_SET_ALWAYS, G_STRUCT_OFFSET( VipsImage, Ysize ), - 1, 1000000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_INT( class, "bands", 4, _( "Bands" ), _( "Number of bands in image" ), VIPS_ARGUMENT_SET_ALWAYS, G_STRUCT_OFFSET( VipsImage, Bands ), - 1, 1000000000, 1 ); + 1, VIPS_MAX_COORD, 1 ); VIPS_ARG_ENUM( class, "format", 5, _( "Format" ), @@ -1175,14 +1175,14 @@ vips_image_class_init( VipsImageClass *class ) _( "Horizontal offset of origin" ), VIPS_ARGUMENT_SET_ALWAYS, G_STRUCT_OFFSET( VipsImage, Xoffset ), - -1000000, 1000000, 0 ); + -VIPS_MAX_COORD, VIPS_MAX_COORD, 0 ); VIPS_ARG_INT( class, "yoffset", 11, _( "Yoffset" ), _( "Vertical offset of origin" ), VIPS_ARGUMENT_SET_ALWAYS, G_STRUCT_OFFSET( VipsImage, Yoffset ), - -1000000, 1000000, 0 ); + -VIPS_MAX_COORD, VIPS_MAX_COORD, 0 ); VIPS_ARG_STRING( class, "filename", 12, _( "Filename" ),