From de232c6478ef885473b9bc299451f5d10350eea4 Mon Sep 17 00:00:00 2001 From: Antonio Vieiro Date: Tue, 9 Jun 2026 03:45:15 -0400 Subject: [PATCH] Backport b56b1acdd12851adbba14c90eb849c254229b6a8 --- THIRD_PARTY_README | 2 +- jdk/src/share/native/sun/awt/giflib/dgif_lib.c | 10 +++++++++- jdk/src/share/native/sun/awt/giflib/gif_lib.h | 2 +- jdk/src/share/native/sun/awt/giflib/gifalloc.c | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/THIRD_PARTY_README b/THIRD_PARTY_README index 52919e77e2d..c6b63bfe7aa 100644 --- a/THIRD_PARTY_README +++ b/THIRD_PARTY_README @@ -2381,7 +2381,7 @@ licenses. ------------------------------------------------------------------------------- -%% This notice is provided with respect to GIFLIB 6.1.2 & libungif 4.1.3, +%% This notice is provided with respect to GIFLIB 6.1.3 & libungif 4.1.3, which may be included with JRE 8, JDK 8, and OpenJDK 8. --- begin of LICENSE --- diff --git a/jdk/src/share/native/sun/awt/giflib/dgif_lib.c b/jdk/src/share/native/sun/awt/giflib/dgif_lib.c index acedde1e01a..f136f0de3d9 100644 --- a/jdk/src/share/native/sun/awt/giflib/dgif_lib.c +++ b/jdk/src/share/native/sun/awt/giflib/dgif_lib.c @@ -1187,7 +1187,15 @@ void DGifDecreaseImageCounter(GifFileType *GifFile) { GifFreeMapObject(GifFile->SavedImages[GifFile->ImageCount].ImageDesc.ColorMap); } - // Realloc array according to the new image counter. + // Avoid a dodgy edge casse in reallocarray() */ + if (GifFile->ImageCount <= 0) { + free(GifFile->SavedImages); + GifFile->SavedImages = NULL; + GifFile->ImageCount = 0; + return; + } + + /* Realloc array according to the new image counter. */ correct_saved_images = (SavedImage *)reallocarray( GifFile->SavedImages, GifFile->ImageCount, sizeof(SavedImage)); if (correct_saved_images != NULL) { diff --git a/jdk/src/share/native/sun/awt/giflib/gif_lib.h b/jdk/src/share/native/sun/awt/giflib/gif_lib.h index 449fe3c2fc9..a74e0765c8b 100644 --- a/jdk/src/share/native/sun/awt/giflib/gif_lib.h +++ b/jdk/src/share/native/sun/awt/giflib/gif_lib.h @@ -39,7 +39,7 @@ extern "C" { #define GIFLIB_MAJOR 6 #define GIFLIB_MINOR 1 -#define GIFLIB_RELEASE 2 +#define GIFLIB_RELEASE 3 #define GIF_ERROR 0 #define GIF_OK 1 diff --git a/jdk/src/share/native/sun/awt/giflib/gifalloc.c b/jdk/src/share/native/sun/awt/giflib/gifalloc.c index 25e03914496..38aa8656973 100644 --- a/jdk/src/share/native/sun/awt/giflib/gifalloc.c +++ b/jdk/src/share/native/sun/awt/giflib/gifalloc.c @@ -167,9 +167,9 @@ ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1, * of table 1. This is very useful if your display is limited to * 16 colors. */ - while (ColorIn1->Colors[CrntSlot - 1].Red == 0 && + while (CrntSlot > 0 && (ColorIn1->Colors[CrntSlot - 1].Red == 0 && ColorIn1->Colors[CrntSlot - 1].Green == 0 && - ColorIn1->Colors[CrntSlot - 1].Blue == 0) { + ColorIn1->Colors[CrntSlot - 1].Blue == 0)) { CrntSlot--; }