chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
# copybara:uncomment package(default_applicable_licenses = ["//tensorflow:license"])
+59
View File
@@ -0,0 +1,59 @@
# Description:
# A library for decoding and encoding GIF images
licenses(["notice"]) # MIT
exports_files(["COPYING"])
cc_library(
name = "gif",
srcs = [
"dgif_lib.c",
"egif_lib.c",
"gif_err.c",
"gif_font.c",
"gif_hash.c",
"gif_hash.h",
"gif_lib_private.h",
"gifalloc.c",
"openbsd-reallocarray.c",
"quantize.c",
],
hdrs = ["gif_lib.h"],
defines = select({
":android": [
"S_IREAD=S_IRUSR",
"S_IWRITE=S_IWUSR",
"S_IEXEC=S_IXUSR",
],
"//conditions:default": [],
}),
includes = ["."],
visibility = ["//visibility:public"],
deps = select({
":windows": [":windows_polyfill"],
"//conditions:default": [],
}),
)
cc_library(
name = "windows_polyfill",
hdrs = ["windows/unistd.h"],
includes = ["windows"],
)
genrule(
name = "windows_unistd_h",
outs = ["windows/unistd.h"],
cmd = "touch $@",
)
config_setting(
name = "windows",
constraint_values = ["@platforms//os:windows"],
)
config_setting(
name = "android",
values = {"crosstool_top": "//external:android/crosstool"},
)
+89
View File
@@ -0,0 +1,89 @@
diff --git a/dgif_lib.c b/dgif_lib.c
index 82fc097..214a0e7 100644
--- a/dgif_lib.c
+++ b/dgif_lib.c
@@ -810,7 +810,8 @@ DGifSetupDecompress(GifFileType *GifFile)
/* coverity[check_return] */
if (InternalRead(GifFile, &CodeSize, 1) < 1) { /* Read Code size from file. */
- return GIF_ERROR; /* Failed to read Code size. */
+ GifFile->Error = D_GIF_ERR_READ_FAILED;
+ return GIF_ERROR; /* Failed to read Code size. */
}
BitsPerPixel = CodeSize;
@@ -1118,6 +1119,31 @@ DGifBufferedInput(GifFileType *GifFile, GifByteType *Buf, GifByteType *NextByte)
return GIF_OK;
}
+/******************************************************************************
+ This routine is called in case of error during parsing image. We need to
+ decrease image counter and reallocate memory for saved images. Not decreasing
+ ImageCount may lead to null pointer dereference, because the last element in
+ SavedImages may point to the spoilt image and null pointer buffers.
+*******************************************************************************/
+void
+DGifDecreaseImageCounter(GifFileType *GifFile)
+{
+ GifFile->ImageCount--;
+ if (GifFile->SavedImages[GifFile->ImageCount].RasterBits != NULL) {
+ free(GifFile->SavedImages[GifFile->ImageCount].RasterBits);
+ }
+ if (GifFile->SavedImages[GifFile->ImageCount].ImageDesc.ColorMap != NULL) {
+ GifFreeMapObject(GifFile->SavedImages[GifFile->ImageCount].ImageDesc.ColorMap);
+ }
+
+ // Realloc array according to the new image counter.
+ SavedImage *correct_saved_images = (SavedImage *)reallocarray(
+ GifFile->SavedImages, GifFile->ImageCount, sizeof(SavedImage));
+ if (correct_saved_images != NULL) {
+ GifFile->SavedImages = correct_saved_images;
+ }
+}
+
/******************************************************************************
This routine reads an entire GIF into core, hanging all its state info off
the GifFileType pointer. Call DGifOpenFileName() or DGifOpenFileHandle()
@@ -1148,17 +1174,20 @@ DGifSlurp(GifFileType *GifFile)
/* Allocate memory for the image */
if (sp->ImageDesc.Width <= 0 || sp->ImageDesc.Height <= 0 ||
sp->ImageDesc.Width > (INT_MAX / sp->ImageDesc.Height)) {
+ DGifDecreaseImageCounter(GifFile);
return GIF_ERROR;
}
ImageSize = sp->ImageDesc.Width * sp->ImageDesc.Height;
if (ImageSize > (SIZE_MAX / sizeof(GifPixelType))) {
+ DGifDecreaseImageCounter(GifFile);
return GIF_ERROR;
}
sp->RasterBits = (unsigned char *)reallocarray(NULL, ImageSize,
sizeof(GifPixelType));
if (sp->RasterBits == NULL) {
+ DGifDecreaseImageCounter(GifFile);
return GIF_ERROR;
}
@@ -1177,13 +1206,17 @@ DGifSlurp(GifFileType *GifFile)
j += InterlacedJumps[i]) {
if (DGifGetLine(GifFile,
sp->RasterBits+j*sp->ImageDesc.Width,
- sp->ImageDesc.Width) == GIF_ERROR)
- return GIF_ERROR;
+ sp->ImageDesc.Width) == GIF_ERROR) {
+ DGifDecreaseImageCounter(GifFile);
+ return GIF_ERROR;
+ }
}
}
else {
- if (DGifGetLine(GifFile,sp->RasterBits,ImageSize)==GIF_ERROR)
- return (GIF_ERROR);
+ if (DGifGetLine(GifFile,sp->RasterBits,ImageSize)==GIF_ERROR) {
+ DGifDecreaseImageCounter(GifFile);
+ return GIF_ERROR;
+ }
}
if (GifFile->ExtensionBlocks) {
+15
View File
@@ -0,0 +1,15 @@
diff -r -u ./fixed_gif_font.c ./gif_font.c
--- ./fixed_gif_font.c 2019-09-05 11:05:25.009598262 -0700
+++ ./gif_font.c 2019-09-05 10:52:45.308389085 -0700
@@ -11,6 +11,11 @@
#include "gif_lib.h"
+// Windows doesn't have strtok_r.
+#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
+#define strtok_r strtok_s
+#endif
+
/*****************************************************************************
Ascii 8 by 8 regular font - only first 128 characters are supported.
*****************************************************************************/
+17
View File
@@ -0,0 +1,17 @@
"""Loads the gif library, used by TF."""
load("//third_party:repo.bzl", "tf_http_archive", "tf_mirror_urls")
def repo():
tf_http_archive(
name = "gif",
build_file = "//third_party/gif:gif.BUILD",
patch_file = [
"//third_party/gif:gif_fix_strtok_r.patch",
"//third_party/gif:gif_fix_image_counter.patch",
],
sha256 = "31da5562f44c5f15d63340a09a4fd62b48c45620cd302f77a6d9acf0077879bd",
strip_prefix = "giflib-5.2.1",
system_build_file = "//third_party/systemlibs:gif.BUILD",
urls = tf_mirror_urls("https://pilotfiber.dl.sourceforge.net/project/giflib/giflib-5.2.1.tar.gz"),
)