8220495: Update GIFlib library to the 5.1.8
Reviewed-by: prr
This commit is contained in:
parent
21d2f5139d
commit
6d23e499bc
src/java.desktop/share
legal
native/libsplashscreen/giflib
@ -1,4 +1,4 @@
|
||||
## GIFLIB v5.1.4
|
||||
## GIFLIB v5.1.8
|
||||
|
||||
### GIFLIB License
|
||||
<pre>
|
||||
|
@ -36,13 +36,16 @@ two modules will be linked. Preserve this property!
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <fcntl.h>
|
||||
/** Begin JDK modifications to support building on Windows **/
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
/** End JDK modifications to support building on Windows **/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#include "gif_lib.h"
|
||||
@ -52,10 +55,14 @@ two modules will be linked. Preserve this property!
|
||||
#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 @@ DGifOpenFileHandle(int FileHandle, int *Error)
|
||||
|
||||
/* 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 @@ DGifOpen(void *userData, InputFunc readFunc, int *Error)
|
||||
|
||||
/* 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 @@ DGifGetScreenDesc(GifFileType *GifFile)
|
||||
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 @@ DGifGetScreenDesc(GifFileType *GifFile)
|
||||
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 @@ DGifGetScreenDesc(GifFileType *GifFile)
|
||||
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 @@ DGifGetRecordType(GifFileType *GifFile, GifRecordType* Type)
|
||||
}
|
||||
|
||||
/* 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 @@ DGifGetRecordType(GifFileType *GifFile, GifRecordType* Type)
|
||||
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 @@ DGifGetImageDesc(GifFileType *GifFile)
|
||||
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 @@ DGifGetImageDesc(GifFileType *GifFile)
|
||||
/* 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 @@ DGifGetImageDesc(GifFileType *GifFile)
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ DGifGetImageDesc(GifFileType *GifFile)
|
||||
|
||||
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 @@ DGifGetExtension(GifFileType *GifFile, int *ExtCode, GifByteType **Extension)
|
||||
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 @@ DGifGetExtension(GifFileType *GifFile, int *ExtCode, GifByteType **Extension)
|
||||
}
|
||||
|
||||
/* 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 @@ DGifGetExtensionNext(GifFileType *GifFile, GifByteType ** Extension)
|
||||
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 @@ DGifGetWord(GifFileType *GifFile, GifWord *Word)
|
||||
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 @@ DGifGetCodeNext(GifFileType *GifFile, GifByteType **CodeBlock)
|
||||
|
||||
/* 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 @@ DGifGetCodeNext(GifFileType *GifFile, GifByteType **CodeBlock)
|
||||
*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 @@ DGifSetupDecompress(GifFileType *GifFile)
|
||||
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 @@ DGifDecompressLine(GifFileType *GifFile, GifPixelType *Line, int LineLen)
|
||||
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 @@ DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf, GifByteType *NextByte)
|
||||
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 @@ DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf, GifByteType *NextByte)
|
||||
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 @@ DGifSlurp(GifFileType *GifFile)
|
||||
|
||||
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 @@ DGifSlurp(GifFileType *GifFile)
|
||||
== 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,
|
||||
|
@ -31,6 +31,11 @@ gif_hash.h - magfic constants and declarations for GIF LZW
|
||||
#ifndef _GIF_HASH_H_
|
||||
#define _GIF_HASH_H_
|
||||
|
||||
/** Begin JDK modifications to support building on Windows **/
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
/** End JDK modifications to support building on Windows **/
|
||||
#include <stdint.h>
|
||||
|
||||
#define HT_SIZE 8192 /* 12bits = 4096 or twice as big! */
|
||||
|
@ -37,19 +37,21 @@ extern "C" {
|
||||
|
||||
#define GIFLIB_MAJOR 5
|
||||
#define GIFLIB_MINOR 1
|
||||
#define GIFLIB_RELEASE 4
|
||||
#define GIFLIB_RELEASE 8
|
||||
|
||||
#define GIF_ERROR 0
|
||||
#define GIF_OK 1
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/** Begin JDK modifications to support building using old compilers**/
|
||||
//#include <stdbool.h>
|
||||
#ifdef bool
|
||||
#undef bool
|
||||
#endif
|
||||
typedef int bool;
|
||||
#define false 0
|
||||
#define true 1
|
||||
/** End JDK modifications to support building using old compilers**/
|
||||
|
||||
#define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */
|
||||
#define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
|
||||
@ -88,7 +90,7 @@ typedef struct ExtensionBlock {
|
||||
#define COMMENT_EXT_FUNC_CODE 0xfe /* comment */
|
||||
#define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control (GIF89) */
|
||||
#define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */
|
||||
#define APPLICATION_EXT_FUNC_CODE 0xff /* application block */
|
||||
#define APPLICATION_EXT_FUNC_CODE 0xff /* application block (GIF89) */
|
||||
} ExtensionBlock;
|
||||
|
||||
typedef struct SavedImage {
|
||||
@ -230,10 +232,10 @@ GifFileType *DGifOpen(void *userPtr, InputFunc readFunc, int *Error); /* new
|
||||
/* These are legacy. You probably do not want to call them directly */
|
||||
int DGifGetScreenDesc(GifFileType *GifFile);
|
||||
int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
|
||||
int DGifGetImageHeader(GifFileType *GifFile);
|
||||
int DGifGetImageDesc(GifFileType *GifFile);
|
||||
int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
|
||||
int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
|
||||
int DGifGetComment(GifFileType *GifFile, char *GifComment);
|
||||
int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
|
||||
GifByteType **GifExtension);
|
||||
int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
|
||||
@ -241,6 +243,7 @@ int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
|
||||
GifByteType **GifCodeBlock);
|
||||
int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
|
||||
int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
|
||||
const char *DGifGetGifVersion(GifFileType *GifFile);
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
@ -274,9 +277,6 @@ extern ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1,
|
||||
GifPixelType ColorTransIn2[]);
|
||||
extern int GifBitSize(int n);
|
||||
|
||||
extern void * reallocarray(void *optr, size_t nmemb, size_t size);
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
Support for the in-core structures allocation (slurp mode).
|
||||
******************************************************************************/
|
||||
|
@ -34,6 +34,10 @@ gif_lib_private.h - internal giflib routines and structures
|
||||
#include "gif_lib.h"
|
||||
#include "gif_hash.h"
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX UINTPTR_MAX
|
||||
#endif
|
||||
|
||||
#define EXTENSION_INTRODUCER 0x21
|
||||
#define DESCRIPTOR_INTRODUCER 0x2c
|
||||
#define TERMINATOR_INTRODUCER 0x3b
|
||||
@ -78,6 +82,11 @@ typedef struct GifFilePrivateType {
|
||||
bool gif89;
|
||||
} GifFilePrivateType;
|
||||
|
||||
#ifndef HAVE_REALLOCARRAY
|
||||
extern void *openbsd_reallocarray(void *optr, size_t nmemb, size_t size);
|
||||
#define reallocarray openbsd_reallocarray
|
||||
#endif
|
||||
|
||||
#endif /* _GIF_LIB_PRIVATE_H */
|
||||
|
||||
/* end */
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "gif_lib.h"
|
||||
#include "gif_lib_private.h"
|
||||
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
|
||||
@ -348,15 +349,17 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom)
|
||||
{
|
||||
if (GifFile->SavedImages == NULL)
|
||||
GifFile->SavedImages = (SavedImage *)malloc(sizeof(SavedImage));
|
||||
else
|
||||
GifFile->SavedImages = (SavedImage *)reallocarray(GifFile->SavedImages,
|
||||
else {
|
||||
SavedImage* newSavedImages = (SavedImage *)reallocarray(GifFile->SavedImages,
|
||||
(GifFile->ImageCount + 1), sizeof(SavedImage));
|
||||
|
||||
if( newSavedImages == NULL)
|
||||
return ((SavedImage *)NULL);
|
||||
GifFile->SavedImages = newSavedImages;
|
||||
}
|
||||
if (GifFile->SavedImages == NULL)
|
||||
return ((SavedImage *)NULL);
|
||||
else {
|
||||
SavedImage *sp = &GifFile->SavedImages[GifFile->ImageCount++];
|
||||
memset((char *)sp, '\0', sizeof(SavedImage));
|
||||
|
||||
if (CopyFrom != NULL) {
|
||||
memcpy((char *)sp, CopyFrom, sizeof(SavedImage));
|
||||
@ -368,7 +371,7 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom)
|
||||
*/
|
||||
|
||||
/* first, the local color map */
|
||||
if (sp->ImageDesc.ColorMap != NULL) {
|
||||
if (CopyFrom->ImageDesc.ColorMap != NULL) {
|
||||
sp->ImageDesc.ColorMap = GifMakeMapObject(
|
||||
CopyFrom->ImageDesc.ColorMap->ColorCount,
|
||||
CopyFrom->ImageDesc.ColorMap->Colors);
|
||||
@ -392,7 +395,7 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom)
|
||||
CopyFrom->ImageDesc.Width);
|
||||
|
||||
/* finally, the extension blocks */
|
||||
if (sp->ExtensionBlocks != NULL) {
|
||||
if (CopyFrom->ExtensionBlocks != NULL) {
|
||||
sp->ExtensionBlocks = (ExtensionBlock *)reallocarray(NULL,
|
||||
CopyFrom->ExtensionBlockCount,
|
||||
sizeof(ExtensionBlock));
|
||||
@ -404,6 +407,9 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom)
|
||||
sizeof(ExtensionBlock) * CopyFrom->ExtensionBlockCount);
|
||||
}
|
||||
}
|
||||
else {
|
||||
memset((char *)sp, '\0', sizeof(SavedImage));
|
||||
}
|
||||
|
||||
return (sp);
|
||||
}
|
||||
|
@ -44,6 +44,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX UINTPTR_MAX
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
|
||||
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
|
||||
@ -51,7 +55,7 @@
|
||||
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
|
||||
|
||||
void *
|
||||
reallocarray(void *optr, size_t nmemb, size_t size)
|
||||
openbsd_reallocarray(void *optr, size_t nmemb, size_t size)
|
||||
{
|
||||
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
|
||||
nmemb > 0 && SIZE_MAX / nmemb < size) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user