From ab18d9b250494249a433068cc3583129d809b322 Mon Sep 17 00:00:00 2001 From: Fabian Giesen Date: Sun, 4 Jul 2021 21:42:44 -0700 Subject: [PATCH] stb_image: Fix two bugs found via VC++ /analyze Also fixes issue #366. --- stb_image.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stb_image.h b/stb_image.h index f2e3430..e68580f 100644 --- a/stb_image.h +++ b/stb_image.h @@ -3821,6 +3821,10 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp else decode_n = z->s->img_n; + // nothing to do if no components requested; check this now to avoid + // accessing uninitialized coutput[0] later + if (decode_n <= 0) { stbi__cleanup_jpeg(z); return NULL; } + // resample and color-convert { int k; @@ -6862,9 +6866,10 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, } if (delays) { - *delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers ); - if (!*delays) + int *new_delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers ); + if (!new_delays) return stbi__load_gif_main_outofmem(&g, out, delays); + *delays = new_delays; delays_size = layers * sizeof(int); } } else {