diff --git a/ChangeLog b/ChangeLog index 298c9fab..49a599cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ - better gifload behaviour for DISPOSAL_UNSPECIFIED [DarthSim] - ban ppm max_value < 0 - add fuzz corpus to dist +- detect read errors correctly in source_sniff 20/6/19 started 8.9.1 - don't use the new source loaders for new_from_file or new_from_buffer, it diff --git a/autogen.sh b/autogen.sh index af5c3d1b..607b795b 100755 --- a/autogen.sh +++ b/autogen.sh @@ -61,4 +61,6 @@ autoheader $LIBTOOLIZE --copy --force --automake automake --add-missing --copy -./configure $* +if test -z "$NOCONFIGURE"; then + ./configure $* +fi diff --git a/libvips/arithmetic/boolean.c b/libvips/arithmetic/boolean.c index c4fcf18d..ad978fe1 100644 --- a/libvips/arithmetic/boolean.c +++ b/libvips/arithmetic/boolean.c @@ -562,7 +562,7 @@ vips_boolean_const_init( VipsBooleanConst *boolean_const ) static int vips_boolean_constv( VipsImage *in, VipsImage **out, - VipsOperationBoolean operation, double *c, int n, va_list ap ) + VipsOperationBoolean operation, const double *c, int n, va_list ap ) { VipsArea *area_c; double *array; @@ -609,7 +609,7 @@ vips_boolean_constv( VipsImage *in, VipsImage **out, */ int vips_boolean_const( VipsImage *in, VipsImage **out, - VipsOperationBoolean boolean, double *c, int n, ... ) + VipsOperationBoolean boolean, const double *c, int n, ... ) { va_list ap; int result; @@ -637,7 +637,8 @@ vips_boolean_const( VipsImage *in, VipsImage **out, * Returns: 0 on success, -1 on error */ int -vips_andimage_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_andimage_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) { va_list ap; int result; @@ -666,7 +667,8 @@ vips_andimage_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_orimage_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_orimage_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) { va_list ap; int result; @@ -695,7 +697,8 @@ vips_orimage_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_eorimage_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_eorimage_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) { va_list ap; int result; @@ -724,7 +727,7 @@ vips_eorimage_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_lshift_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_lshift_const( VipsImage *in, VipsImage **out, const double *c, int n, ... ) { va_list ap; int result; @@ -753,7 +756,7 @@ vips_lshift_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_rshift_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_rshift_const( VipsImage *in, VipsImage **out, const double *c, int n, ... ) { va_list ap; int result; diff --git a/libvips/arithmetic/linear.c b/libvips/arithmetic/linear.c index 4a376a55..ebf4fb33 100644 --- a/libvips/arithmetic/linear.c +++ b/libvips/arithmetic/linear.c @@ -453,7 +453,7 @@ vips_linear_init( VipsLinear *linear ) static int vips_linearv( VipsImage *in, VipsImage **out, - double *a, double *b, int n, va_list ap ) + const double *a, const double *b, int n, va_list ap ) { VipsArea *area_a; VipsArea *area_b; @@ -500,7 +500,8 @@ vips_linearv( VipsImage *in, VipsImage **out, * Returns: 0 on success, -1 on error */ int -vips_linear( VipsImage *in, VipsImage **out, double *a, double *b, int n, ... ) +vips_linear( VipsImage *in, VipsImage **out, + const double *a, const double *b, int n, ... ) { va_list ap; int result; diff --git a/libvips/arithmetic/math2.c b/libvips/arithmetic/math2.c index cbcd2b99..dd3e5323 100644 --- a/libvips/arithmetic/math2.c +++ b/libvips/arithmetic/math2.c @@ -420,7 +420,7 @@ vips_math2_const_init( VipsMath2Const *math2_const ) static int vips_math2_constv( VipsImage *in, VipsImage **out, - VipsOperationMath2 math2, double *c, int n, va_list ap ) + VipsOperationMath2 math2, const double *c, int n, va_list ap ) { VipsArea *area_c; double *array; @@ -470,7 +470,7 @@ vips_math2_constv( VipsImage *in, VipsImage **out, */ int vips_math2_const( VipsImage *in, VipsImage **out, - VipsOperationMath2 math2, double *c, int n, ... ) + VipsOperationMath2 math2, const double *c, int n, ... ) { va_list ap; int result; @@ -496,7 +496,7 @@ vips_math2_const( VipsImage *in, VipsImage **out, * Returns: 0 on success, -1 on error */ int -vips_pow_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_pow_const( VipsImage *in, VipsImage **out, const double *c, int n, ... ) { va_list ap; int result; @@ -523,7 +523,7 @@ vips_pow_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_wop_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_wop_const( VipsImage *in, VipsImage **out, const double *c, int n, ... ) { va_list ap; int result; diff --git a/libvips/arithmetic/relational.c b/libvips/arithmetic/relational.c index f2f8f817..d740ea5c 100644 --- a/libvips/arithmetic/relational.c +++ b/libvips/arithmetic/relational.c @@ -598,7 +598,7 @@ vips_relational_const_init( VipsRelationalConst *relational_const ) static int vips_relational_constv( VipsImage *in, VipsImage **out, - VipsOperationRelational relational, double *c, int n, va_list ap ) + VipsOperationRelational relational, const double *c, int n, va_list ap ) { VipsArea *area_c; double *array; @@ -645,7 +645,7 @@ vips_relational_constv( VipsImage *in, VipsImage **out, */ int vips_relational_const( VipsImage *in, VipsImage **out, - VipsOperationRelational relational, double *c, int n, ... ) + VipsOperationRelational relational, const double *c, int n, ... ) { va_list ap; int result; @@ -671,7 +671,7 @@ vips_relational_const( VipsImage *in, VipsImage **out, * Returns: 0 on success, -1 on error */ int -vips_equal_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_equal_const( VipsImage *in, VipsImage **out, const double *c, int n, ... ) { va_list ap; int result; @@ -698,7 +698,8 @@ vips_equal_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_notequal_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_notequal_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) { va_list ap; int result; @@ -725,7 +726,7 @@ vips_notequal_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_less_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_less_const( VipsImage *in, VipsImage **out, const double *c, int n, ... ) { va_list ap; int result; @@ -752,7 +753,7 @@ vips_less_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_lesseq_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_lesseq_const( VipsImage *in, VipsImage **out, const double *c, int n, ... ) { va_list ap; int result; @@ -779,7 +780,7 @@ vips_lesseq_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_more_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_more_const( VipsImage *in, VipsImage **out, const double *c, int n, ... ) { va_list ap; int result; @@ -806,7 +807,7 @@ vips_more_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) * Returns: 0 on success, -1 on error */ int -vips_moreeq_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_moreeq_const( VipsImage *in, VipsImage **out, const double *c, int n, ... ) { va_list ap; int result; diff --git a/libvips/arithmetic/remainder.c b/libvips/arithmetic/remainder.c index 75df8f4d..3c994345 100644 --- a/libvips/arithmetic/remainder.c +++ b/libvips/arithmetic/remainder.c @@ -333,7 +333,7 @@ vips_remainder_const_init( VipsRemainderConst *remainder_const ) static int vips_remainder_constv( VipsImage *in, VipsImage **out, - double *c, int n, va_list ap ) + const double *c, int n, va_list ap ) { VipsArea *area_c; double *array; @@ -379,7 +379,8 @@ vips_remainder_constv( VipsImage *in, VipsImage **out, * Returns: 0 on success, -1 on error */ int -vips_remainder_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +vips_remainder_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) { va_list ap; int result; diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index f85e6a47..a0669d55 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -535,7 +535,7 @@ vips_foreign_find_load( const char *name ) */ if( !vips_existsf( "%s", filename ) ) { vips_error( "VipsForeignLoad", - _( "file \"%s\" not found" ), name ); + _( "file \"%s\" not readable" ), name ); return( NULL ); } diff --git a/libvips/include/vips/arithmetic.h b/libvips/include/vips/arithmetic.h index ce95399a..3c9c7aa9 100644 --- a/libvips/include/vips/arithmetic.h +++ b/libvips/include/vips/arithmetic.h @@ -185,14 +185,14 @@ int vips_multiply( VipsImage *left, VipsImage *right, VipsImage **out, ... ) int vips_divide( VipsImage *left, VipsImage *right, VipsImage **out, ... ) __attribute__((sentinel)); int vips_linear( VipsImage *in, VipsImage **out, - double *a, double *b, int n, ... ) + const double *a, const double *b, int n, ... ) __attribute__((sentinel)); int vips_linear1( VipsImage *in, VipsImage **out, double a, double b, ... ) __attribute__((sentinel)); int vips_remainder( VipsImage *left, VipsImage *right, VipsImage **out, ... ) __attribute__((sentinel)); int vips_remainder_const( VipsImage *in, VipsImage **out, - double *c, int n, ... ) + const double *c, int n, ... ) __attribute__((sentinel)); int vips_remainder_const1( VipsImage *in, VipsImage **out, double c, ... ) @@ -279,19 +279,25 @@ int vips_more( VipsImage *left, VipsImage *right, VipsImage **out, ... ) int vips_moreeq( VipsImage *left, VipsImage *right, VipsImage **out, ... ) __attribute__((sentinel)); int vips_relational_const( VipsImage *in, VipsImage **out, - VipsOperationRelational relational, double *c, int n, ... ) + VipsOperationRelational relational, const double *c, int n, ... ) __attribute__((sentinel)); -int vips_equal_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_equal_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_notequal_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_notequal_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_less_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_less_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_lesseq_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_lesseq_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_more_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_more_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_moreeq_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_moreeq_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); int vips_relational_const1( VipsImage *in, VipsImage **out, VipsOperationRelational relational, double c, ... ) @@ -324,17 +330,22 @@ int vips_rshift( VipsImage *left, VipsImage *right, VipsImage **out, ... ) __attribute__((sentinel)); int vips_boolean_const( VipsImage *in, VipsImage **out, - VipsOperationBoolean boolean, double *c, int n, ... ) + VipsOperationBoolean boolean, const double *c, int n, ... ) __attribute__((sentinel)); -int vips_andimage_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_andimage_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_orimage_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_orimage_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_eorimage_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_eorimage_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_lshift_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_lshift_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_rshift_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_rshift_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); int vips_boolean_const1( VipsImage *in, VipsImage **out, VipsOperationBoolean boolean, double c, ... ) @@ -358,11 +369,13 @@ int vips_pow( VipsImage *left, VipsImage *right, VipsImage **out, ... ) int vips_wop( VipsImage *left, VipsImage *right, VipsImage **out, ... ) __attribute__((sentinel)); int vips_math2_const( VipsImage *in, VipsImage **out, - VipsOperationMath2 math2, double *c, int n, ... ) + VipsOperationMath2 math2, const double *c, int n, ... ) __attribute__((sentinel)); -int vips_pow_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_pow_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); -int vips_wop_const( VipsImage *in, VipsImage **out, double *c, int n, ... ) +int vips_wop_const( VipsImage *in, VipsImage **out, + const double *c, int n, ... ) __attribute__((sentinel)); int vips_math2_const1( VipsImage *in, VipsImage **out, VipsOperationMath2 math2, double c, ... ) diff --git a/libvips/include/vips/connection.h b/libvips/include/vips/connection.h index d12a33a6..35132733 100644 --- a/libvips/include/vips/connection.h +++ b/libvips/include/vips/connection.h @@ -222,7 +222,7 @@ const void *vips_source_map( VipsSource *source, size_t *length ); VipsBlob *vips_source_map_blob( VipsSource *source ); gint64 vips_source_seek( VipsSource *source, gint64 offset, int whence ); int vips_source_rewind( VipsSource *source ); -size_t vips_source_sniff_at_most( VipsSource *source, +gint64 vips_source_sniff_at_most( VipsSource *source, unsigned char **data, size_t length ); unsigned char *vips_source_sniff( VipsSource *source, size_t length ); gint64 vips_source_length( VipsSource *source ); diff --git a/libvips/iofuncs/memory.c b/libvips/iofuncs/memory.c index db396e51..517cf301 100644 --- a/libvips/iofuncs/memory.c +++ b/libvips/iofuncs/memory.c @@ -358,7 +358,7 @@ vips_tracked_malloc( size_t size ) * @flags: flags for open() * @...: open mode * - * Exactly as open(2), but the number of files current open via + * Exactly as open(2), but the number of files currently open via * vips_tracked_open() is available via vips_tracked_get_files(). This is used * by the vips operation cache to drop cache when the number of files * available is low. diff --git a/libvips/iofuncs/source.c b/libvips/iofuncs/source.c index af482d11..4f07b0ce 100644 --- a/libvips/iofuncs/source.c +++ b/libvips/iofuncs/source.c @@ -1191,7 +1191,7 @@ vips_source_length( VipsSource *source ) } /** - * vips_source_peek: + * vips_source_sniff_at_most: * @source: peek this source * @data: return a pointer to the bytes read here * @length: max number of bytes to read @@ -1203,7 +1203,7 @@ vips_source_length( VipsSource *source ) * * Returns: number of bytes read, or -1 on error. */ -size_t +gint64 vips_source_sniff_at_most( VipsSource *source, unsigned char **data, size_t length ) { @@ -1257,12 +1257,14 @@ unsigned char * vips_source_sniff( VipsSource *source, size_t length ) { unsigned char *data; - size_t bytes_read; + gint64 bytes_read; if( vips_source_test_features( source ) ) return( NULL ); bytes_read = vips_source_sniff_at_most( source, &data, length ); + if( bytes_read == -1 ) + return( NULL ); if( bytes_read < length ) return( NULL ); diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index 99c67641..b749541d 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -634,6 +634,14 @@ vips__open( const char *filename, int flags, ... ) mode = va_arg( ap, int ); va_end( ap ); + /* Various bad things happen if you accidentally open a directory as a + * file. + */ + if( g_file_test( filename, G_FILE_TEST_IS_DIR ) ) { + errno = EISDIR; + return( -1 ); + } + fd = g_open( filename, flags, mode ); #ifdef OS_WIN32 @@ -1090,6 +1098,10 @@ vips__seek_no_error( int fd, gint64 pos, int whence ) #ifdef OS_WIN32 new_pos = _lseeki64( fd, pos, whence ); #else /*!OS_WIN32*/ + /* On error, eg. opening a directory and seeking to the end, lseek() + * on linux seems to return 9223372036854775807 ((1 << 63) - 1) + * rather than (off_t) -1 for reasons I don't understand. + */ new_pos = lseek( fd, pos, whence ); #endif /*OS_WIN32*/ @@ -1145,29 +1157,26 @@ vips__ftruncate( int fd, gint64 pos ) return( 0 ); } -/* TRUE if file exists. +/* TRUE if file exists and is not a directory. */ gboolean vips_existsf( const char *name, ... ) { va_list ap; char *path; - int result; + gboolean result; va_start( ap, name ); path = g_strdup_vprintf( name, ap ); va_end( ap ); - result = g_access( path, R_OK ); + /* A regular (not a directory) file. + */ + result = g_file_test( path, G_FILE_TEST_IS_REGULAR ); g_free( path ); - /* access() can fail for various reasons, especially under things - * like selinux. Only return FALSE if we are certain the file does not - * exist. - */ - return( result == 0 || - errno != ENOENT ); + return( result ); } #ifdef OS_WIN32