diff options
Diffstat (limited to 'source/blender/imbuf/intern')
-rw-r--r-- | source/blender/imbuf/intern/IMB_filetype.h | 22 | ||||
-rw-r--r-- | source/blender/imbuf/intern/anim_movie.c | 11 | ||||
-rw-r--r-- | source/blender/imbuf/intern/dds/dds_api.h | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/oiio/openimageio_api.h | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.h | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/radiance_hdr.c | 31 |
6 files changed, 41 insertions, 29 deletions
diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h index 104458ffa7a..bf6aef3ecd3 100644 --- a/source/blender/imbuf/intern/IMB_filetype.h +++ b/source/blender/imbuf/intern/IMB_filetype.h @@ -41,7 +41,7 @@ typedef struct ImFileType { * \note that this may only read in a small part of the files header, * see: #IMB_ispic_type for details. */ - bool (*is_a)(const unsigned char *buf, const size_t size); + bool (*is_a)(const unsigned char *buf, size_t size); /** Load an image from memory. */ struct ImBuf *(*load)(const unsigned char *mem, @@ -93,7 +93,7 @@ void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty); /** \name Format: PNG (#IMB_FTYPE_PNG) * \{ */ -bool imb_is_a_png(const unsigned char *mem, const size_t size); +bool imb_is_a_png(const unsigned char *mem, size_t size); struct ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, @@ -106,7 +106,7 @@ bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: TARGA (#IMB_FTYPE_TGA) * \{ */ -bool imb_is_a_targa(const unsigned char *buf, const size_t size); +bool imb_is_a_targa(const unsigned char *buf, size_t size); struct ImBuf *imb_loadtarga(const unsigned char *mem, size_t size, int flags, @@ -119,7 +119,7 @@ bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: IRIS (#IMB_FTYPE_IMAGIC) * \{ */ -bool imb_is_a_iris(const unsigned char *mem, const size_t size); +bool imb_is_a_iris(const unsigned char *mem, size_t size); /** * Read in a B/W RGB or RGBA iris image file and return an image buffer. */ @@ -135,7 +135,7 @@ bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JP2 (#IMB_FTYPE_JP2) * \{ */ -bool imb_is_a_jp2(const unsigned char *buf, const size_t size); +bool imb_is_a_jp2(const unsigned char *buf, size_t size); struct ImBuf *imb_load_jp2(const unsigned char *mem, size_t size, int flags, @@ -151,7 +151,7 @@ bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: JPEG (#IMB_FTYPE_JPG) * \{ */ -bool imb_is_a_jpeg(const unsigned char *mem, const size_t size); +bool imb_is_a_jpeg(const unsigned char *mem, size_t size); bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags); struct ImBuf *imb_load_jpeg(const unsigned char *buffer, size_t size, @@ -164,7 +164,7 @@ struct ImBuf *imb_load_jpeg(const unsigned char *buffer, /** \name Format: BMP (#IMB_FTYPE_BMP) * \{ */ -bool imb_is_a_bmp(const unsigned char *buf, const size_t size); +bool imb_is_a_bmp(const unsigned char *buf, size_t size); struct ImBuf *imb_bmp_decode(const unsigned char *mem, size_t size, int flags, @@ -178,7 +178,7 @@ bool imb_savebmp(struct ImBuf *ibuf, const char *filepath, int flags); /** \name Format: CINEON (#IMB_FTYPE_CINEON) * \{ */ -bool imb_is_a_cineon(const unsigned char *buf, const size_t size); +bool imb_is_a_cineon(const unsigned char *buf, size_t size); bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_cineon(const unsigned char *mem, size_t size, @@ -191,7 +191,7 @@ struct ImBuf *imb_load_cineon(const unsigned char *mem, /** \name Format: DPX (#IMB_FTYPE_DPX) * \{ */ -bool imb_is_a_dpx(const unsigned char *buf, const size_t size); +bool imb_is_a_dpx(const unsigned char *buf, size_t size); bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_dpx(const unsigned char *mem, size_t size, @@ -204,7 +204,7 @@ struct ImBuf *imb_load_dpx(const unsigned char *mem, /** \name Format: HDR (#IMB_FTYPE_RADHDR) * \{ */ -bool imb_is_a_hdr(const unsigned char *buf, const size_t size); +bool imb_is_a_hdr(const unsigned char *buf, size_t size); struct ImBuf *imb_loadhdr(const unsigned char *mem, size_t size, int flags, @@ -218,7 +218,7 @@ bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags); * \{ */ void imb_inittiff(void); -bool imb_is_a_tiff(const unsigned char *buf, const size_t size); +bool imb_is_a_tiff(const unsigned char *buf, size_t size); /** * Loads a TIFF file. * \param mem: Memory containing the TIFF file. diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 1d81653c7cd..6a05b681c88 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -879,7 +879,7 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); # else - /* Scale with swscale then flip image over Y axis. */ + /* Scale with swscale. */ int *dstStride = anim->pFrameRGB->linesize; uint8_t **dst = anim->pFrameRGB->data; const int dstStride2[4] = {dstStride[0], 0, 0, 0}; @@ -896,11 +896,12 @@ static void ffmpeg_postprocess(struct anim *anim) dst2, dstStride2); - bottom = (unsigned char *)ibuf->rect; - top = bottom + ibuf->x * (ibuf->y - 1) * 4; + /* Flip destination image buffer over Y axis. */ + bottom = (unsigned char *)dst[0]; + top = bottom + anim->x * (anim->y - 1) * 4; - h = (ibuf->y + 1) / 2; - w = ibuf->x; + h = (anim->y + 1) / 2; + w = anim->x; for (y = 0; y < h; y++) { unsigned char tmp[4]; diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index 931c4f267f9..2d540f13a52 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -26,7 +26,7 @@ extern "C" { #endif -bool imb_is_a_dds(const unsigned char *mem, const size_t size); +bool imb_is_a_dds(const unsigned char *mem, size_t size); bool imb_save_dds(struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_dds(const unsigned char *mem, size_t size, diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h index 659050cdb00..1201bd1b5e0 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.h +++ b/source/blender/imbuf/intern/oiio/openimageio_api.h @@ -31,7 +31,7 @@ extern "C" { struct ImBuf; -bool imb_is_a_photoshop(const unsigned char *mem, const size_t size); +bool imb_is_a_photoshop(const unsigned char *mem, size_t size); int imb_save_photoshop(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h index 14336620926..4321c95db30 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.h +++ b/source/blender/imbuf/intern/openexr/openexr_api.h @@ -36,7 +36,7 @@ void imb_exitopenexr(void); * Test presence of OpenEXR file. * \param mem: pointer to loaded OpenEXR bit-stream. */ -bool imb_is_a_openexr(const unsigned char *mem, const size_t size); +bool imb_is_a_openexr(const unsigned char *mem, size_t size); bool imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags); diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 7f4e4dd31df..925ef0a8502 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -77,7 +77,7 @@ static const unsigned char *oldreadcolrs(RGBE *scan, scan[0][BLU] = *mem++; scan[0][EXP] = *mem++; if (scan[0][RED] == 1 && scan[0][GRN] == 1 && scan[0][BLU] == 1) { - for (i = scan[0][EXP] << rshift; i > 0; i--) { + for (i = scan[0][EXP] << rshift; i > 0 && len > 0; i--) { COPY_RGBE(scan[-1], scan[0]); scan++; len--; @@ -227,7 +227,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, int found = 0; int width = 0, height = 0; const unsigned char *ptr, *mem_eof = mem + size; - char oriY[80], oriX[80]; + char oriY[3], oriX[3]; if (!imb_is_a_hdr(mem, size)) { return NULL; @@ -244,22 +244,33 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, } } - if ((found && (x < (size + 2))) == 0) { + if ((found && (x < (size - 1))) == 0) { /* Data not found! */ return NULL; } - if (sscanf((const char *)&mem[x + 1], - "%79s %d %79s %d", - (char *)&oriY, - &height, - (char *)&oriX, - &width) != 4) { + x++; + + /* sscanf requires a null-terminated buffer argument */ + char buf[32] = {0}; + memcpy(buf, &mem[x], MIN2(sizeof(buf) - 1, size - x)); + + if (sscanf(buf, "%2s %d %2s %d", (char *)&oriY, &height, (char *)&oriX, &width) != 4) { + return NULL; + } + + if (width < 1 || height < 1) { return NULL; } + /* Checking that width x height does not extend past mem_eof is not easily possible + * since the format uses RLE compression. Can cause excessive memory allocation to occur. */ + /* find end of this line, data right behind it */ - ptr = (const unsigned char *)strchr((const char *)&mem[x + 1], '\n'); + ptr = (const unsigned char *)strchr((const char *)&mem[x], '\n'); + if (ptr == NULL || ptr >= mem_eof) { + return NULL; + } ptr++; if (flags & IB_test) { |