From 29490cd03b3f9ca4c6f0f1654630111ac260a3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=B9=94=E5=BC=82?= Date: Mon, 29 Jul 2024 10:42:06 +0800 Subject: [PATCH] =?UTF-8?q?cherry=20pick=20bf55881=20from=20https://gitee.?= =?UTF-8?q?com/chen-qiao-yi/third=5Fparty=5Fastc-encoder/pulls/35=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E7=A0=81=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈乔异 --- Source/stb_image.h | 18 ++++++++++++------ Source/tinyexr.h | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/stb_image.h b/Source/stb_image.h index 0f8459a..1d297d8 100644 --- a/Source/stb_image.h +++ b/Source/stb_image.h @@ -1428,7 +1428,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 ); } @@ -6907,8 +6907,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; @@ -6923,8 +6926,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) ); @@ -6935,7 +6941,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 3e0aba9..e3e6c32 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; -- Gitee