--- old/src/java.desktop/share/native/libsplashscreen/giflib/dgif_lib.c 2019-03-20 23:58:18.000000000 -0700 +++ new/src/java.desktop/share/native/libsplashscreen/giflib/dgif_lib.c 2019-03-20 23:58:18.000000000 -0700 @@ -36,13 +36,16 @@ #include #include #include +/** Begin JDK modifications to support building on Windows **/ +#ifndef _WIN32 +#include +#endif +/** End JDK modifications to support building on Windows **/ #include #include #ifdef _WIN32 #include -#else -#include #endif /* _WIN32 */ #include "gif_lib.h" @@ -52,10 +55,14 @@ #define UNSIGNED_LITTLE_ENDIAN(lo, hi) ((lo) | ((hi) << 8)) /* avoid extra function call in case we use fread (TVT) */ -#define READ(_gif,_buf,_len) \ - (((GifFilePrivateType*)_gif->Private)->Read ? \ - ((GifFilePrivateType*)_gif->Private)->Read(_gif,_buf,_len) : \ - fread(_buf,1,_len,((GifFilePrivateType*)_gif->Private)->File)) +/** JDK modification "inline" is dropped to support c89 **/ +static /**inline**/ int InternalRead(GifFileType *gif, GifByteType *buf, int len) { + //fprintf(stderr, "### Read: %d\n", len); + return + (((GifFilePrivateType*)gif->Private)->Read ? + ((GifFilePrivateType*)gif->Private)->Read(gif,buf,len) : + fread(buf,1,len,((GifFilePrivateType*)gif->Private)->File)); +} static int DGifGetWord(GifFileType *GifFile, GifWord *Word); static int DGifSetupDecompress(GifFileType *GifFile); @@ -142,7 +149,7 @@ /* Let's see if this is a GIF file: */ /* coverity[check_return] */ - if (READ(GifFile, (unsigned char *)Buf, GIF_STAMP_LEN) != GIF_STAMP_LEN) { + if (InternalRead(GifFile, (unsigned char *)Buf, GIF_STAMP_LEN) != GIF_STAMP_LEN) { if (Error != NULL) *Error = D_GIF_ERR_READ_FAILED; (void)fclose(f); @@ -219,7 +226,7 @@ /* Lets see if this is a GIF file: */ /* coverity[check_return] */ - if (READ(GifFile, (unsigned char *)Buf, GIF_STAMP_LEN) != GIF_STAMP_LEN) { + if (InternalRead(GifFile, (unsigned char *)Buf, GIF_STAMP_LEN) != GIF_STAMP_LEN) { if (Error != NULL) *Error = D_GIF_ERR_READ_FAILED; free((char *)Private); @@ -276,7 +283,7 @@ DGifGetWord(GifFile, &GifFile->SHeight) == GIF_ERROR) return GIF_ERROR; - if (READ(GifFile, Buf, 3) != 3) { + if (InternalRead(GifFile, Buf, 3) != 3) { GifFile->Error = D_GIF_ERR_READ_FAILED; GifFreeMapObject(GifFile->SColorMap); GifFile->SColorMap = NULL; @@ -300,7 +307,7 @@ GifFile->SColorMap->SortFlag = SortFlag; for (i = 0; i < GifFile->SColorMap->ColorCount; i++) { /* coverity[check_return] */ - if (READ(GifFile, Buf, 3) != 3) { + if (InternalRead(GifFile, Buf, 3) != 3) { GifFreeMapObject(GifFile->SColorMap); GifFile->SColorMap = NULL; GifFile->Error = D_GIF_ERR_READ_FAILED; @@ -314,9 +321,25 @@ GifFile->SColorMap = NULL; } + /* + * No check here for whether the background color is in range for the + * screen color map. Possibly there should be. + */ + return GIF_OK; } +const char * +DGifGetGifVersion(GifFileType *GifFile) +{ + GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private; + + if (Private->gif89) + return GIF89_STAMP; + else + return GIF87_STAMP; +} + /****************************************************************************** This routine should be called before any attempt to read an image. ******************************************************************************/ @@ -333,11 +356,12 @@ } /* coverity[check_return] */ - if (READ(GifFile, &Buf, 1) != 1) { + if (InternalRead(GifFile, &Buf, 1) != 1) { GifFile->Error = D_GIF_ERR_READ_FAILED; return GIF_ERROR; } + //fprintf(stderr, "### DGifGetRecordType: %02x\n", Buf); switch (Buf) { case DESCRIPTOR_INTRODUCER: *Type = IMAGE_DESC_RECORD_TYPE; @@ -357,17 +381,12 @@ return GIF_OK; } -/****************************************************************************** - This routine should be called before any attempt to read an image. - Note it is assumed the Image desc. header has been read. -******************************************************************************/ int -DGifGetImageDesc(GifFileType *GifFile) +DGifGetImageHeader(GifFileType *GifFile) { unsigned int BitsPerPixel; GifByteType Buf[3]; GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; - SavedImage *sp; if (!IS_READABLE(Private)) { /* This file was NOT open for reading: */ @@ -380,7 +399,7 @@ DGifGetWord(GifFile, &GifFile->Image.Width) == GIF_ERROR || DGifGetWord(GifFile, &GifFile->Image.Height) == GIF_ERROR) return GIF_ERROR; - if (READ(GifFile, Buf, 1) != 1) { + if (InternalRead(GifFile, Buf, 1) != 1) { GifFile->Error = D_GIF_ERR_READ_FAILED; GifFreeMapObject(GifFile->Image.ColorMap); GifFile->Image.ColorMap = NULL; @@ -407,7 +426,7 @@ /* Get the image local color map: */ for (i = 0; i < GifFile->Image.ColorMap->ColorCount; i++) { /* coverity[check_return] */ - if (READ(GifFile, Buf, 3) != 3) { + if (InternalRead(GifFile, Buf, 3) != 3) { GifFreeMapObject(GifFile->Image.ColorMap); GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Image.ColorMap = NULL; @@ -419,6 +438,33 @@ } } + Private->PixelCount = (long)GifFile->Image.Width * + (long)GifFile->Image.Height; + + /* Reset decompress algorithm parameters. */ + return DGifSetupDecompress(GifFile); +} + +/****************************************************************************** + This routine should be called before any attempt to read an image. + Note it is assumed the Image desc. header has been read. +******************************************************************************/ +int +DGifGetImageDesc(GifFileType *GifFile) +{ + GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; + SavedImage *sp; + + if (!IS_READABLE(Private)) { + /* This file was NOT open for reading: */ + GifFile->Error = D_GIF_ERR_NOT_READABLE; + return GIF_ERROR; + } + + if (DGifGetImageHeader(GifFile) == GIF_ERROR) { + return GIF_ERROR; + } + if (GifFile->SavedImages) { SavedImage* new_saved_images = (SavedImage *)reallocarray(GifFile->SavedImages, @@ -453,11 +499,7 @@ GifFile->ImageCount++; - Private->PixelCount = (long)GifFile->Image.Width * - (long)GifFile->Image.Height; - - /* Reset decompress algorithm parameters. */ - return DGifSetupDecompress(GifFile); + return GIF_OK; } /****************************************************************************** @@ -550,6 +592,7 @@ GifByteType Buf; GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; + //fprintf(stderr, "### -> DGifGetExtension:\n"); if (!IS_READABLE(Private)) { /* This file was NOT open for reading: */ GifFile->Error = D_GIF_ERR_NOT_READABLE; @@ -557,11 +600,12 @@ } /* coverity[check_return] */ - if (READ(GifFile, &Buf, 1) != 1) { + if (InternalRead(GifFile, &Buf, 1) != 1) { GifFile->Error = D_GIF_ERR_READ_FAILED; return GIF_ERROR; } *ExtCode = Buf; + //fprintf(stderr, "### <- DGifGetExtension: %02x, about to call next\n", Buf); return DGifGetExtensionNext(GifFile, Extension); } @@ -577,20 +621,24 @@ GifByteType Buf; GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; - if (READ(GifFile, &Buf, 1) != 1) { + //fprintf(stderr, "### -> DGifGetExtensionNext\n"); + if (InternalRead(GifFile, &Buf, 1) != 1) { GifFile->Error = D_GIF_ERR_READ_FAILED; return GIF_ERROR; } + //fprintf(stderr, "### DGifGetExtensionNext sees %d\n", Buf); + if (Buf > 0) { *Extension = Private->Buf; /* Use private unused buffer. */ (*Extension)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */ /* coverity[tainted_data,check_return] */ - if (READ(GifFile, &((*Extension)[1]), Buf) != Buf) { + if (InternalRead(GifFile, &((*Extension)[1]), Buf) != Buf) { GifFile->Error = D_GIF_ERR_READ_FAILED; return GIF_ERROR; } } else *Extension = NULL; + //fprintf(stderr, "### <- DGifGetExtensionNext: %p\n", Extension); return GIF_OK; } @@ -707,7 +755,7 @@ unsigned char c[2]; /* coverity[check_return] */ - if (READ(GifFile, c, 2) != 2) { + if (InternalRead(GifFile, c, 2) != 2) { GifFile->Error = D_GIF_ERR_READ_FAILED; return GIF_ERROR; } @@ -752,7 +800,7 @@ /* coverity[tainted_data_argument] */ /* coverity[check_return] */ - if (READ(GifFile, &Buf, 1) != 1) { + if (InternalRead(GifFile, &Buf, 1) != 1) { GifFile->Error = D_GIF_ERR_READ_FAILED; return GIF_ERROR; } @@ -762,7 +810,7 @@ *CodeBlock = Private->Buf; /* Use private unused buffer. */ (*CodeBlock)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */ /* coverity[tainted_data] */ - if (READ(GifFile, &((*CodeBlock)[1]), Buf) != Buf) { + if (InternalRead(GifFile, &((*CodeBlock)[1]), Buf) != Buf) { GifFile->Error = D_GIF_ERR_READ_FAILED; return GIF_ERROR; } @@ -787,7 +835,7 @@ GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; /* coverity[check_return] */ - if (READ(GifFile, &CodeSize, 1) < 1) { /* Read Code size from file. */ + if (InternalRead(GifFile, &CodeSize, 1) < 1) { /* Read Code size from file. */ return GIF_ERROR; /* Failed to read Code size. */ } BitsPerPixel = CodeSize; @@ -921,7 +969,7 @@ while (StackPtr != 0 && i < LineLen) Line[i++] = Stack[--StackPtr]; } - if (LastCode != NO_SUCH_CODE && Prefix[Private->RunningCode - 2] == NO_SUCH_CODE) { + if (LastCode != NO_SUCH_CODE && Private->RunningCode - 2 < LZ_MAX_CODE && Prefix[Private->RunningCode - 2] == NO_SUCH_CODE) { Prefix[Private->RunningCode - 2] = LastCode; if (CrntCode == Private->RunningCode - 2) { @@ -1069,7 +1117,7 @@ if (Buf[0] == 0) { /* Needs to read the next buffer - this one is empty: */ /* coverity[check_return] */ - if (READ(GifFile, Buf, 1) != 1) { + if (InternalRead(GifFile, Buf, 1) != 1) { GifFile->Error = D_GIF_ERR_READ_FAILED; return GIF_ERROR; } @@ -1081,7 +1129,7 @@ GifFile->Error = D_GIF_ERR_IMAGE_DEFECT; return GIF_ERROR; } - if (READ(GifFile, &Buf[1], Buf[0]) != Buf[0]) { + if (InternalRead(GifFile, &Buf[1], Buf[0]) != Buf[0]) { GifFile->Error = D_GIF_ERR_READ_FAILED; return GIF_ERROR; } @@ -1124,7 +1172,7 @@ sp = &GifFile->SavedImages[GifFile->ImageCount - 1]; /* Allocate memory for the image */ - if (sp->ImageDesc.Width < 0 && sp->ImageDesc.Height < 0 && + if (sp->ImageDesc.Width <= 0 || sp->ImageDesc.Height <= 0 || sp->ImageDesc.Width > (INT_MAX / sp->ImageDesc.Height)) { return GIF_ERROR; } @@ -1184,9 +1232,11 @@ == GIF_ERROR) return (GIF_ERROR); } - while (ExtData != NULL) { + for (;;) { if (DGifGetExtensionNext(GifFile, &ExtData) == GIF_ERROR) return (GIF_ERROR); + if (ExtData == NULL) + break; /* Continue the extension block */ if (ExtData != NULL) if (GifAddExtensionBlock(&GifFile->ExtensionBlockCount,