diff --git a/Source/stb_image.h b/Source/stb_image.h index 5e807a0a6e7cdbfbbf48dff5f5d3f3693c2bc851..be014b2e94fe178d89d10f505d80e7fda27dac84 100644 --- a/Source/stb_image.h +++ b/Source/stb_image.h @@ -1446,7 +1446,7 @@ STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int * stbi__start_mem(&s,buffer,len); result = (unsigned char*) stbi__load_gif_main(&s, delays, x, y, z, comp, req_comp); - if (stbi__vertically_flip_on_load) { + if (stbi__vertically_flip_on_load && result) { stbi__vertical_flip_slices( result, *x, *y, *z, *comp ); } @@ -6991,8 +6991,11 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, if (out) { void *tmp = (stbi_uc*) STBI_REALLOC_SIZED( out, out_size, layers * stride ); - if (!tmp) - return stbi__load_gif_main_outofmem(&g, out, delays); + if (!tmp) { + void *ret = stbi__load_gif_main_outofmem(&g, out, delays); + if (delays && *delays) *delays = 0; + return ret; + } else { out = (stbi_uc*) tmp; out_size = layers * stride; @@ -7007,8 +7010,11 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, } } else { out = (stbi_uc*)stbi__malloc( layers * stride ); - if (!out) - return stbi__load_gif_main_outofmem(&g, out, delays); + if (!out) { + void *ret = stbi__load_gif_main_outofmem(&g, out, delays); + if (delays && *delays) *delays = 0; + return ret; + } out_size = layers * stride; if (delays) { *delays = (int*) stbi__malloc( layers * sizeof(int) ); @@ -7019,7 +7025,7 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, } memcpy( out + ((layers - 1) * stride), u, stride ); if (layers >= 2) { - two_back = out - 2 * stride; + two_back = out + (layers - 2) * stride; } if (delays) { diff --git a/Source/tinyexr.h b/Source/tinyexr.h index 3e0aba94c6ba8540c82e9ab9dbfad69a5002defe..e3e6c32f0cb7af341063c70a17a72eaea0f7874d 100644 --- a/Source/tinyexr.h +++ b/Source/tinyexr.h @@ -7764,7 +7764,7 @@ static int rleUncompress(int inLength, int maxLength, const signed char in[], int count = *in++; inLength -= 2; - if (0 > (maxLength -= count + 1)) return 0; + if (0 > (maxLength -= count + 1) || inLength < 0) return 0; memset(out, *reinterpret_cast(in), count + 1); out += count + 1;