diff options
Diffstat (limited to 'source/blender/imbuf/intern/png.c')
-rw-r--r-- | source/blender/imbuf/intern/png.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index dbae641f707..25fc6a1cddf 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -59,19 +59,21 @@ BLI_INLINE unsigned short UPSAMPLE_8_TO_16(const unsigned char _val) return (_val << 8) + _val; } -int imb_is_a_png(const unsigned char *mem) +bool imb_is_a_png(const unsigned char *mem, size_t size) { - int ret_val = 0; + const int num_to_check = 8; + if (size < num_to_check) { + return false; + } + bool ok = false; - if (mem) { #if (PNG_LIBPNG_VER_MAJOR == 1) && (PNG_LIBPNG_VER_MINOR == 2) - /* Older version of libpng doesn't use const pointer to memory. */ - ret_val = !png_sig_cmp((png_bytep)mem, 0, 8); + /* Older version of libpng doesn't use const pointer to memory. */ + ok = !png_sig_cmp((png_bytep)mem, 0, num_to_check); #else - ret_val = !png_sig_cmp(mem, 0, 8); + ok = !png_sig_cmp(mem, 0, num_to_check); #endif - } - return ret_val; + return ok; } static void Flush(png_structp png_ptr) @@ -119,7 +121,7 @@ BLI_INLINE unsigned short ftoshort(float val) return unit_float_to_ushort_clamp(val); } -int imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags) +bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags) { png_structp png_ptr; png_infop info_ptr; @@ -521,7 +523,7 @@ static void imb_png_warning(png_structp UNUSED(png_ptr), png_const_charp message * and with new libpng it became too much picky, giving a warning on * the splash screen even. */ - if ((G.debug & G_DEBUG) == 0 && STREQLEN(message, "iCCP", 4)) { + if ((G.debug & G_DEBUG) == 0 && STRPREFIX(message, "iCCP")) { return; } fprintf(stderr, "libpng warning: %s\n", message); @@ -549,7 +551,7 @@ ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colors float *to_float; unsigned int channels; - if (imb_is_a_png(mem) == 0) { + if (imb_is_a_png(mem, size) == 0) { return NULL; } |