# HG changeset patch # User stefano # Date 1281087405 0 # Node ID 97c3fe501477200473ec30151f6e1abff4661f68 # Parent c37229a98056e552145ba4ccdf282f8e2f6c683a Deprecate avcodec_check_dimensions() in favor of the new function av_check_image_size() declared in libavcore/imgutils.h. diff -r c37229a98056 -r 97c3fe501477 avcore.h --- a/avcore.h Fri Jul 30 08:42:22 2010 +0000 +++ b/avcore.h Fri Aug 06 09:36:45 2010 +0000 @@ -27,7 +27,7 @@ #include #define LIBAVCORE_VERSION_MAJOR 0 -#define LIBAVCORE_VERSION_MINOR 2 +#define LIBAVCORE_VERSION_MINOR 3 #define LIBAVCORE_VERSION_MICRO 0 #define LIBAVCORE_VERSION_INT AV_VERSION_INT(LIBAVCORE_VERSION_MAJOR, \ diff -r c37229a98056 -r 97c3fe501477 imgutils.c --- a/imgutils.c Fri Jul 30 08:42:22 2010 +0000 +++ b/imgutils.c Fri Aug 06 09:36:45 2010 +0000 @@ -95,3 +95,22 @@ return total_size; } + +typedef struct ImgUtils { + const AVClass *class; + int log_offset; + void *log_ctx; +} ImgUtils; + +static const AVClass imgutils_class = { "IMGUTILS", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(ImgUtils, log_offset), offsetof(ImgUtils, log_ctx) }; + +int av_check_image_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx) +{ + ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx }; + + if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8) + return 0; + + av_log(&imgutils, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h); + return AVERROR(EINVAL); +} diff -r c37229a98056 -r 97c3fe501477 imgutils.h --- a/imgutils.h Fri Jul 30 08:42:22 2010 +0000 +++ b/imgutils.h Fri Aug 06 09:36:45 2010 +0000 @@ -50,4 +50,16 @@ int av_fill_image_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4]); +/** + * Check if the given dimension of an image is valid, meaning that all + * bytes of the image can be addressed with a signed int. + * + * @param w the width of the picture + * @param h the height of the picture + * @param log_offset the offset to sum to the log level for logging with log_ctx + * @param log_ctx the parent logging context, it may be NULL + * @return >= 0 if valid, a negative error code otherwise + */ +int av_check_image_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx); + #endif /* AVCORE_IMGUTILS_H */