[giflib] Add giflib (#2062)

* Add initial version of giflib

* Fix a memory leak in dgif_target

This commit fixes a memory that was caused by calling the wrong
close function.

* giflib: Minor bug fixes that also addressees most comments from Doris
This commit is contained in:
Vincent Ulitzsch 2019-01-08 20:17:29 +01:00 committed by Max Moroz
parent 231f91a5be
commit 834a138b39
6 changed files with 135 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
FROM gcr.io/oss-fuzz-base/base-builder
MAINTAINER esr@thyrsus.com
RUN apt-get update && apt-get install -y make autoconf automake libtool wget
RUN git clone --depth=1 https://git.code.sf.net/p/giflib/code $SRC/giflib-code
COPY *.c *.options build.sh $SRC/

18
projects/giflib/build.sh Executable file
View File

@ -0,0 +1,18 @@
cd $SRC/giflib-code
./autogen.sh
make
cd ..
for file in $SRC/*.c;
do
name=$(basename $file .c)
$CC $CFLAGS -c -I giflib-code/lib ${file} -o ${name}.o
$CXX $CXXFLAGS -std=c++11 -I giflib-code/lib ${name}.o \
-o $OUT/${name} -lFuzzingEngine giflib-code/lib/.libs/libgif.a
done
# Place dict and config in OUT
wget -O $OUT/gif.dict \
https://raw.githubusercontent.com/mirrorer/afl/master/dictionaries/gif.dict \
&> /dev/null
cp $SRC/*.options $OUT/
find $SRC/giflib-code -iname "*.gif" -exec \
zip -ujq $OUT/dgif_target_seed_corpus.zip "{}" \;

View File

@ -0,0 +1,70 @@
/*****************************************************************************
gif2rgb - convert GIF to 24-bit RGB pixel triples or vice-versa
*****************************************************************************/
/***************************************************************************
Toshio Kuratomi had written this in a comment about the rgb2gif code:
Besides fixing bugs, what's really needed is for someone to work out how to
calculate a colormap for writing GIFs from rgb sources. Right now, an rgb
source that has only two colors (b/w) is being converted into an 8 bit GIF....
Which is horrendously wasteful without compression.
I (ESR) took this off the main to-do list in 2012 because I don't think
the GIFLIB project actually needs to be in the converters-and-tools business.
Plenty of hackers do that; our job is to supply stable library capability
with our utilities mainly interesting as test tools.
***************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include <fcntl.h>
#include <stdint.h>
#ifdef _WIN32
#include <io.h>
#endif /* _WIN32 */
#include "gif_lib.h"
#define PROGRAM_NAME "gif2rgb"
/* ===========================================================================
* Display error message and exit
*/
void fuzz_error(const char *msg)
{
fprintf(stderr, "%s: %s\n", "gif2rgb_fuzzer", msg);
exit(1);
}
/* end */
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{
char *inFileName = "/tmp/gif.gif";
FILE *in = fopen(inFileName, "w");
if(in==NULL){
fuzz_error("failed fopen");
}
int Error = 0;
if (fwrite(Data, 1, (unsigned)Size, in) != Size)
fuzz_error("failed fwrite");
if (fclose(in))
fuzz_error("failed fclose");
GifFileType *GifFile;
GifFile = DGifOpenFileName(inFileName, &Error);
if (GifFile == NULL){
return 0;
}
DGifSlurp(GifFile);
DGifCloseFile(GifFile, &Error);
return 0;
}

View File

@ -0,0 +1,2 @@
[libfuzzer]
dict = gif.dict

19
projects/giflib/gif.dict Normal file
View File

@ -0,0 +1,19 @@
#
# AFL dictionary for GIF images
# -----------------------------
#
# Created by Michal Zalewski <lcamtuf@google.com>
#
header_87a="87a"
header_89a="89a"
header_gif="GIF"
marker_2c=","
marker_3b=";"
section_2101="!\x01\x12"
section_21f9="!\xf9\x04"
section_21fe="!\xfe"
section_21ff="!\xff\x11"

View File

@ -0,0 +1,5 @@
homepage: "http://giflib.sourceforge.net/"
primary_contact: "esr@thyrsus.com"
auto_ccs:
- "vincent.ulitzsch@live.de"
- "bshas3@gmail.com"