提交 7f0bea39 编写于 作者: S serb

8220495: Update GIFlib library to the 5.1.8

Reviewed-by: prr
上级 528b1d08
...@@ -1612,7 +1612,7 @@ July 15, 2018 ...@@ -1612,7 +1612,7 @@ July 15, 2018
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
%% This notice is provided with respect to GIFLIB 5.1.1 & libungif 4.1.3, %% This notice is provided with respect to GIFLIB 5.1.8 & libungif 4.1.3,
which may be included with JRE 8, JDK 8, and OpenJDK 8. which may be included with JRE 8, JDK 8, and OpenJDK 8.
--- begin of LICENSE --- --- begin of LICENSE ---
......
...@@ -36,13 +36,16 @@ two modules will be linked. Preserve this property! ...@@ -36,13 +36,16 @@ two modules will be linked. Preserve this property!
#include <limits.h> #include <limits.h>
#include <stdint.h> #include <stdint.h>
#include <fcntl.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 <stdio.h>
#include <string.h> #include <string.h>
#ifdef _WIN32 #ifdef _WIN32
#include <io.h> #include <io.h>
#else
#include <unistd.h>
#endif /* _WIN32 */ #endif /* _WIN32 */
#include "gif_lib.h" #include "gif_lib.h"
...@@ -52,10 +55,14 @@ two modules will be linked. Preserve this property! ...@@ -52,10 +55,14 @@ two modules will be linked. Preserve this property!
#define UNSIGNED_LITTLE_ENDIAN(lo, hi) ((lo) | ((hi) << 8)) #define UNSIGNED_LITTLE_ENDIAN(lo, hi) ((lo) | ((hi) << 8))
/* avoid extra function call in case we use fread (TVT) */ /* avoid extra function call in case we use fread (TVT) */
#define READ(_gif,_buf,_len) \ /** JDK modification "inline" is dropped to support c89 **/
(((GifFilePrivateType*)_gif->Private)->Read ? \ static /**inline**/ int InternalRead(GifFileType *gif, GifByteType *buf, int len) {
((GifFilePrivateType*)_gif->Private)->Read(_gif,_buf,_len) : \ //fprintf(stderr, "### Read: %d\n", len);
fread(_buf,1,_len,((GifFilePrivateType*)_gif->Private)->File)) 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 DGifGetWord(GifFileType *GifFile, GifWord *Word);
static int DGifSetupDecompress(GifFileType *GifFile); static int DGifSetupDecompress(GifFileType *GifFile);
...@@ -142,7 +149,7 @@ DGifOpenFileHandle(int FileHandle, int *Error) ...@@ -142,7 +149,7 @@ DGifOpenFileHandle(int FileHandle, int *Error)
/* Let's see if this is a GIF file: */ /* Let's see if this is a GIF file: */
/* coverity[check_return] */ /* 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) if (Error != NULL)
*Error = D_GIF_ERR_READ_FAILED; *Error = D_GIF_ERR_READ_FAILED;
(void)fclose(f); (void)fclose(f);
...@@ -219,7 +226,7 @@ DGifOpen(void *userData, InputFunc readFunc, int *Error) ...@@ -219,7 +226,7 @@ DGifOpen(void *userData, InputFunc readFunc, int *Error)
/* Lets see if this is a GIF file: */ /* Lets see if this is a GIF file: */
/* coverity[check_return] */ /* 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) if (Error != NULL)
*Error = D_GIF_ERR_READ_FAILED; *Error = D_GIF_ERR_READ_FAILED;
free((char *)Private); free((char *)Private);
...@@ -276,7 +283,7 @@ DGifGetScreenDesc(GifFileType *GifFile) ...@@ -276,7 +283,7 @@ DGifGetScreenDesc(GifFileType *GifFile)
DGifGetWord(GifFile, &GifFile->SHeight) == GIF_ERROR) DGifGetWord(GifFile, &GifFile->SHeight) == GIF_ERROR)
return GIF_ERROR; return GIF_ERROR;
if (READ(GifFile, Buf, 3) != 3) { if (InternalRead(GifFile, Buf, 3) != 3) {
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
GifFreeMapObject(GifFile->SColorMap); GifFreeMapObject(GifFile->SColorMap);
GifFile->SColorMap = NULL; GifFile->SColorMap = NULL;
...@@ -300,7 +307,7 @@ DGifGetScreenDesc(GifFileType *GifFile) ...@@ -300,7 +307,7 @@ DGifGetScreenDesc(GifFileType *GifFile)
GifFile->SColorMap->SortFlag = SortFlag; GifFile->SColorMap->SortFlag = SortFlag;
for (i = 0; i < GifFile->SColorMap->ColorCount; i++) { for (i = 0; i < GifFile->SColorMap->ColorCount; i++) {
/* coverity[check_return] */ /* coverity[check_return] */
if (READ(GifFile, Buf, 3) != 3) { if (InternalRead(GifFile, Buf, 3) != 3) {
GifFreeMapObject(GifFile->SColorMap); GifFreeMapObject(GifFile->SColorMap);
GifFile->SColorMap = NULL; GifFile->SColorMap = NULL;
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
...@@ -314,9 +321,25 @@ DGifGetScreenDesc(GifFileType *GifFile) ...@@ -314,9 +321,25 @@ DGifGetScreenDesc(GifFileType *GifFile)
GifFile->SColorMap = NULL; 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; 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. This routine should be called before any attempt to read an image.
******************************************************************************/ ******************************************************************************/
...@@ -333,11 +356,12 @@ DGifGetRecordType(GifFileType *GifFile, GifRecordType* Type) ...@@ -333,11 +356,12 @@ DGifGetRecordType(GifFileType *GifFile, GifRecordType* Type)
} }
/* coverity[check_return] */ /* coverity[check_return] */
if (READ(GifFile, &Buf, 1) != 1) { if (InternalRead(GifFile, &Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR; return GIF_ERROR;
} }
//fprintf(stderr, "### DGifGetRecordType: %02x\n", Buf);
switch (Buf) { switch (Buf) {
case DESCRIPTOR_INTRODUCER: case DESCRIPTOR_INTRODUCER:
*Type = IMAGE_DESC_RECORD_TYPE; *Type = IMAGE_DESC_RECORD_TYPE;
...@@ -357,17 +381,12 @@ DGifGetRecordType(GifFileType *GifFile, GifRecordType* Type) ...@@ -357,17 +381,12 @@ DGifGetRecordType(GifFileType *GifFile, GifRecordType* Type)
return GIF_OK; 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 int
DGifGetImageDesc(GifFileType *GifFile) DGifGetImageHeader(GifFileType *GifFile)
{ {
unsigned int BitsPerPixel; unsigned int BitsPerPixel;
GifByteType Buf[3]; GifByteType Buf[3];
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
SavedImage *sp;
if (!IS_READABLE(Private)) { if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */ /* This file was NOT open for reading: */
...@@ -380,7 +399,7 @@ DGifGetImageDesc(GifFileType *GifFile) ...@@ -380,7 +399,7 @@ DGifGetImageDesc(GifFileType *GifFile)
DGifGetWord(GifFile, &GifFile->Image.Width) == GIF_ERROR || DGifGetWord(GifFile, &GifFile->Image.Width) == GIF_ERROR ||
DGifGetWord(GifFile, &GifFile->Image.Height) == GIF_ERROR) DGifGetWord(GifFile, &GifFile->Image.Height) == GIF_ERROR)
return GIF_ERROR; return GIF_ERROR;
if (READ(GifFile, Buf, 1) != 1) { if (InternalRead(GifFile, Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
GifFreeMapObject(GifFile->Image.ColorMap); GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Image.ColorMap = NULL; GifFile->Image.ColorMap = NULL;
...@@ -407,7 +426,7 @@ DGifGetImageDesc(GifFileType *GifFile) ...@@ -407,7 +426,7 @@ DGifGetImageDesc(GifFileType *GifFile)
/* Get the image local color map: */ /* Get the image local color map: */
for (i = 0; i < GifFile->Image.ColorMap->ColorCount; i++) { for (i = 0; i < GifFile->Image.ColorMap->ColorCount; i++) {
/* coverity[check_return] */ /* coverity[check_return] */
if (READ(GifFile, Buf, 3) != 3) { if (InternalRead(GifFile, Buf, 3) != 3) {
GifFreeMapObject(GifFile->Image.ColorMap); GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
GifFile->Image.ColorMap = NULL; GifFile->Image.ColorMap = NULL;
...@@ -419,6 +438,33 @@ DGifGetImageDesc(GifFileType *GifFile) ...@@ -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) { if (GifFile->SavedImages) {
SavedImage* new_saved_images = SavedImage* new_saved_images =
(SavedImage *)reallocarray(GifFile->SavedImages, (SavedImage *)reallocarray(GifFile->SavedImages,
...@@ -453,11 +499,7 @@ DGifGetImageDesc(GifFileType *GifFile) ...@@ -453,11 +499,7 @@ DGifGetImageDesc(GifFileType *GifFile)
GifFile->ImageCount++; GifFile->ImageCount++;
Private->PixelCount = (long)GifFile->Image.Width * return GIF_OK;
(long)GifFile->Image.Height;
/* Reset decompress algorithm parameters. */
return DGifSetupDecompress(GifFile);
} }
/****************************************************************************** /******************************************************************************
...@@ -550,6 +592,7 @@ DGifGetExtension(GifFileType *GifFile, int *ExtCode, GifByteType **Extension) ...@@ -550,6 +592,7 @@ DGifGetExtension(GifFileType *GifFile, int *ExtCode, GifByteType **Extension)
GifByteType Buf; GifByteType Buf;
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
//fprintf(stderr, "### -> DGifGetExtension:\n");
if (!IS_READABLE(Private)) { if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */ /* This file was NOT open for reading: */
GifFile->Error = D_GIF_ERR_NOT_READABLE; GifFile->Error = D_GIF_ERR_NOT_READABLE;
...@@ -557,11 +600,12 @@ DGifGetExtension(GifFileType *GifFile, int *ExtCode, GifByteType **Extension) ...@@ -557,11 +600,12 @@ DGifGetExtension(GifFileType *GifFile, int *ExtCode, GifByteType **Extension)
} }
/* coverity[check_return] */ /* coverity[check_return] */
if (READ(GifFile, &Buf, 1) != 1) { if (InternalRead(GifFile, &Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR; return GIF_ERROR;
} }
*ExtCode = Buf; *ExtCode = Buf;
//fprintf(stderr, "### <- DGifGetExtension: %02x, about to call next\n", Buf);
return DGifGetExtensionNext(GifFile, Extension); return DGifGetExtensionNext(GifFile, Extension);
} }
...@@ -577,20 +621,24 @@ DGifGetExtensionNext(GifFileType *GifFile, GifByteType ** Extension) ...@@ -577,20 +621,24 @@ DGifGetExtensionNext(GifFileType *GifFile, GifByteType ** Extension)
GifByteType Buf; GifByteType Buf;
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; 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; GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR; return GIF_ERROR;
} }
//fprintf(stderr, "### DGifGetExtensionNext sees %d\n", Buf);
if (Buf > 0) { if (Buf > 0) {
*Extension = Private->Buf; /* Use private unused buffer. */ *Extension = Private->Buf; /* Use private unused buffer. */
(*Extension)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */ (*Extension)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */
/* coverity[tainted_data,check_return] */ /* 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; GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR; return GIF_ERROR;
} }
} else } else
*Extension = NULL; *Extension = NULL;
//fprintf(stderr, "### <- DGifGetExtensionNext: %p\n", Extension);
return GIF_OK; return GIF_OK;
} }
...@@ -707,7 +755,7 @@ DGifGetWord(GifFileType *GifFile, GifWord *Word) ...@@ -707,7 +755,7 @@ DGifGetWord(GifFileType *GifFile, GifWord *Word)
unsigned char c[2]; unsigned char c[2];
/* coverity[check_return] */ /* coverity[check_return] */
if (READ(GifFile, c, 2) != 2) { if (InternalRead(GifFile, c, 2) != 2) {
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR; return GIF_ERROR;
} }
...@@ -752,7 +800,7 @@ DGifGetCodeNext(GifFileType *GifFile, GifByteType **CodeBlock) ...@@ -752,7 +800,7 @@ DGifGetCodeNext(GifFileType *GifFile, GifByteType **CodeBlock)
/* coverity[tainted_data_argument] */ /* coverity[tainted_data_argument] */
/* coverity[check_return] */ /* coverity[check_return] */
if (READ(GifFile, &Buf, 1) != 1) { if (InternalRead(GifFile, &Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR; return GIF_ERROR;
} }
...@@ -762,7 +810,7 @@ DGifGetCodeNext(GifFileType *GifFile, GifByteType **CodeBlock) ...@@ -762,7 +810,7 @@ DGifGetCodeNext(GifFileType *GifFile, GifByteType **CodeBlock)
*CodeBlock = Private->Buf; /* Use private unused buffer. */ *CodeBlock = Private->Buf; /* Use private unused buffer. */
(*CodeBlock)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */ (*CodeBlock)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */
/* coverity[tainted_data] */ /* coverity[tainted_data] */
if (READ(GifFile, &((*CodeBlock)[1]), Buf) != Buf) { if (InternalRead(GifFile, &((*CodeBlock)[1]), Buf) != Buf) {
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR; return GIF_ERROR;
} }
...@@ -787,7 +835,7 @@ DGifSetupDecompress(GifFileType *GifFile) ...@@ -787,7 +835,7 @@ DGifSetupDecompress(GifFileType *GifFile)
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
/* coverity[check_return] */ /* 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. */ return GIF_ERROR; /* Failed to read Code size. */
} }
BitsPerPixel = CodeSize; BitsPerPixel = CodeSize;
...@@ -921,7 +969,7 @@ DGifDecompressLine(GifFileType *GifFile, GifPixelType *Line, int LineLen) ...@@ -921,7 +969,7 @@ DGifDecompressLine(GifFileType *GifFile, GifPixelType *Line, int LineLen)
while (StackPtr != 0 && i < LineLen) while (StackPtr != 0 && i < LineLen)
Line[i++] = Stack[--StackPtr]; 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; Prefix[Private->RunningCode - 2] = LastCode;
if (CrntCode == Private->RunningCode - 2) { if (CrntCode == Private->RunningCode - 2) {
...@@ -1069,7 +1117,7 @@ DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf, GifByteType *NextByte) ...@@ -1069,7 +1117,7 @@ DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf, GifByteType *NextByte)
if (Buf[0] == 0) { if (Buf[0] == 0) {
/* Needs to read the next buffer - this one is empty: */ /* Needs to read the next buffer - this one is empty: */
/* coverity[check_return] */ /* coverity[check_return] */
if (READ(GifFile, Buf, 1) != 1) { if (InternalRead(GifFile, Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED; GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR; return GIF_ERROR;
} }
...@@ -1081,7 +1129,7 @@ DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf, GifByteType *NextByte) ...@@ -1081,7 +1129,7 @@ DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf, GifByteType *NextByte)
GifFile->Error = D_GIF_ERR_IMAGE_DEFECT; GifFile->Error = D_GIF_ERR_IMAGE_DEFECT;
return GIF_ERROR; 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; GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR; return GIF_ERROR;
} }
...@@ -1124,7 +1172,7 @@ DGifSlurp(GifFileType *GifFile) ...@@ -1124,7 +1172,7 @@ DGifSlurp(GifFileType *GifFile)
sp = &GifFile->SavedImages[GifFile->ImageCount - 1]; sp = &GifFile->SavedImages[GifFile->ImageCount - 1];
/* Allocate memory for the image */ /* 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)) { sp->ImageDesc.Width > (INT_MAX / sp->ImageDesc.Height)) {
return GIF_ERROR; return GIF_ERROR;
} }
...@@ -1184,9 +1232,11 @@ DGifSlurp(GifFileType *GifFile) ...@@ -1184,9 +1232,11 @@ DGifSlurp(GifFileType *GifFile)
== GIF_ERROR) == GIF_ERROR)
return (GIF_ERROR); return (GIF_ERROR);
} }
while (ExtData != NULL) { for (;;) {
if (DGifGetExtensionNext(GifFile, &ExtData) == GIF_ERROR) if (DGifGetExtensionNext(GifFile, &ExtData) == GIF_ERROR)
return (GIF_ERROR); return (GIF_ERROR);
if (ExtData == NULL)
break;
/* Continue the extension block */ /* Continue the extension block */
if (ExtData != NULL) if (ExtData != NULL)
if (GifAddExtensionBlock(&GifFile->ExtensionBlockCount, if (GifAddExtensionBlock(&GifFile->ExtensionBlockCount,
......
...@@ -31,6 +31,11 @@ gif_hash.h - magfic constants and declarations for GIF LZW ...@@ -31,6 +31,11 @@ gif_hash.h - magfic constants and declarations for GIF LZW
#ifndef _GIF_HASH_H_ #ifndef _GIF_HASH_H_
#define _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> #include <stdint.h>
#define HT_SIZE 8192 /* 12bits = 4096 or twice as big! */ #define HT_SIZE 8192 /* 12bits = 4096 or twice as big! */
......
...@@ -37,19 +37,21 @@ extern "C" { ...@@ -37,19 +37,21 @@ extern "C" {
#define GIFLIB_MAJOR 5 #define GIFLIB_MAJOR 5
#define GIFLIB_MINOR 1 #define GIFLIB_MINOR 1
#define GIFLIB_RELEASE 4 #define GIFLIB_RELEASE 8
#define GIF_ERROR 0 #define GIF_ERROR 0
#define GIF_OK 1 #define GIF_OK 1
#include <stddef.h> #include <stddef.h>
/** Begin JDK modifications to support building using old compilers**/
//#include <stdbool.h>
#ifdef bool #ifdef bool
#undef bool #undef bool
#endif #endif
typedef int bool; typedef int bool;
#define false 0 #define false 0
#define true 1 #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 "GIFVER" /* First chars in file - GIF stamp. */
#define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1 #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
...@@ -88,7 +90,7 @@ typedef struct ExtensionBlock { ...@@ -88,7 +90,7 @@ typedef struct ExtensionBlock {
#define COMMENT_EXT_FUNC_CODE 0xfe /* comment */ #define COMMENT_EXT_FUNC_CODE 0xfe /* comment */
#define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control (GIF89) */ #define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control (GIF89) */
#define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */ #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; } ExtensionBlock;
typedef struct SavedImage { typedef struct SavedImage {
...@@ -230,10 +232,10 @@ GifFileType *DGifOpen(void *userPtr, InputFunc readFunc, int *Error); /* new ...@@ -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 */ /* These are legacy. You probably do not want to call them directly */
int DGifGetScreenDesc(GifFileType *GifFile); int DGifGetScreenDesc(GifFileType *GifFile);
int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType); int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
int DGifGetImageHeader(GifFileType *GifFile);
int DGifGetImageDesc(GifFileType *GifFile); int DGifGetImageDesc(GifFileType *GifFile);
int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen); int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel); int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
int DGifGetComment(GifFileType *GifFile, char *GifComment);
int DGifGetExtension(GifFileType *GifFile, int *GifExtCode, int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
GifByteType **GifExtension); GifByteType **GifExtension);
int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension); int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
...@@ -241,6 +243,7 @@ int DGifGetCode(GifFileType *GifFile, int *GifCodeSize, ...@@ -241,6 +243,7 @@ int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
GifByteType **GifCodeBlock); GifByteType **GifCodeBlock);
int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock); int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
int DGifGetLZCodes(GifFileType *GifFile, int *GifCode); int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
const char *DGifGetGifVersion(GifFileType *GifFile);
/****************************************************************************** /******************************************************************************
...@@ -274,9 +277,6 @@ extern ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1, ...@@ -274,9 +277,6 @@ extern ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1,
GifPixelType ColorTransIn2[]); GifPixelType ColorTransIn2[]);
extern int GifBitSize(int n); 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). Support for the in-core structures allocation (slurp mode).
******************************************************************************/ ******************************************************************************/
......
...@@ -34,6 +34,10 @@ gif_lib_private.h - internal giflib routines and structures ...@@ -34,6 +34,10 @@ gif_lib_private.h - internal giflib routines and structures
#include "gif_lib.h" #include "gif_lib.h"
#include "gif_hash.h" #include "gif_hash.h"
#ifndef SIZE_MAX
#define SIZE_MAX UINTPTR_MAX
#endif
#define EXTENSION_INTRODUCER 0x21 #define EXTENSION_INTRODUCER 0x21
#define DESCRIPTOR_INTRODUCER 0x2c #define DESCRIPTOR_INTRODUCER 0x2c
#define TERMINATOR_INTRODUCER 0x3b #define TERMINATOR_INTRODUCER 0x3b
...@@ -78,6 +82,11 @@ typedef struct GifFilePrivateType { ...@@ -78,6 +82,11 @@ typedef struct GifFilePrivateType {
bool gif89; bool gif89;
} GifFilePrivateType; } 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 */ #endif /* _GIF_LIB_PRIVATE_H */
/* end */ /* end */
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <string.h> #include <string.h>
#include "gif_lib.h" #include "gif_lib.h"
#include "gif_lib_private.h"
#define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MAX(x, y) (((x) > (y)) ? (x) : (y))
...@@ -348,15 +349,17 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom) ...@@ -348,15 +349,17 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom)
{ {
if (GifFile->SavedImages == NULL) if (GifFile->SavedImages == NULL)
GifFile->SavedImages = (SavedImage *)malloc(sizeof(SavedImage)); GifFile->SavedImages = (SavedImage *)malloc(sizeof(SavedImage));
else else {
GifFile->SavedImages = (SavedImage *)reallocarray(GifFile->SavedImages, SavedImage* newSavedImages = (SavedImage *)reallocarray(GifFile->SavedImages,
(GifFile->ImageCount + 1), sizeof(SavedImage)); (GifFile->ImageCount + 1), sizeof(SavedImage));
if( newSavedImages == NULL)
return ((SavedImage *)NULL);
GifFile->SavedImages = newSavedImages;
}
if (GifFile->SavedImages == NULL) if (GifFile->SavedImages == NULL)
return ((SavedImage *)NULL); return ((SavedImage *)NULL);
else { else {
SavedImage *sp = &GifFile->SavedImages[GifFile->ImageCount++]; SavedImage *sp = &GifFile->SavedImages[GifFile->ImageCount++];
memset((char *)sp, '\0', sizeof(SavedImage));
if (CopyFrom != NULL) { if (CopyFrom != NULL) {
memcpy((char *)sp, CopyFrom, sizeof(SavedImage)); memcpy((char *)sp, CopyFrom, sizeof(SavedImage));
...@@ -368,7 +371,7 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom) ...@@ -368,7 +371,7 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom)
*/ */
/* first, the local color map */ /* first, the local color map */
if (sp->ImageDesc.ColorMap != NULL) { if (CopyFrom->ImageDesc.ColorMap != NULL) {
sp->ImageDesc.ColorMap = GifMakeMapObject( sp->ImageDesc.ColorMap = GifMakeMapObject(
CopyFrom->ImageDesc.ColorMap->ColorCount, CopyFrom->ImageDesc.ColorMap->ColorCount,
CopyFrom->ImageDesc.ColorMap->Colors); CopyFrom->ImageDesc.ColorMap->Colors);
...@@ -392,7 +395,7 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom) ...@@ -392,7 +395,7 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom)
CopyFrom->ImageDesc.Width); CopyFrom->ImageDesc.Width);
/* finally, the extension blocks */ /* finally, the extension blocks */
if (sp->ExtensionBlocks != NULL) { if (CopyFrom->ExtensionBlocks != NULL) {
sp->ExtensionBlocks = (ExtensionBlock *)reallocarray(NULL, sp->ExtensionBlocks = (ExtensionBlock *)reallocarray(NULL,
CopyFrom->ExtensionBlockCount, CopyFrom->ExtensionBlockCount,
sizeof(ExtensionBlock)); sizeof(ExtensionBlock));
...@@ -404,6 +407,9 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom) ...@@ -404,6 +407,9 @@ GifMakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom)
sizeof(ExtensionBlock) * CopyFrom->ExtensionBlockCount); sizeof(ExtensionBlock) * CopyFrom->ExtensionBlockCount);
} }
} }
else {
memset((char *)sp, '\0', sizeof(SavedImage));
}
return (sp); return (sp);
} }
......
...@@ -44,6 +44,10 @@ ...@@ -44,6 +44,10 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef SIZE_MAX
#define SIZE_MAX UINTPTR_MAX
#endif
/* /*
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
...@@ -51,7 +55,7 @@ ...@@ -51,7 +55,7 @@
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
void * 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) && if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && SIZE_MAX / nmemb < size) { nmemb > 0 && SIZE_MAX / nmemb < size) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册