aboutsummaryrefslogtreecommitdiff
path: root/projects/leptonica
diff options
context:
space:
mode:
authorAdamKorcz <44787359+AdamKorcz@users.noreply.github.com>2020-04-29 00:52:50 +0100
committerGitHub <noreply@github.com>2020-04-28 16:52:50 -0700
commita8a9213b2317cd74acd7029b5a85e4003528fefa (patch)
tree0c00173e091cdc5704c975ce78d8627c70760acb /projects/leptonica
parentc580d0d626247017dede2847869e1eb8a3705ee1 (diff)
downloadoss-fuzz-a8a9213b2317cd74acd7029b5a85e4003528fefa.tar.gz
[Leptonica] Updating build-files to reflect moving fuzzers to upstream (#3728)
Diffstat (limited to 'projects/leptonica')
-rw-r--r--projects/leptonica/Dockerfile3
-rwxr-xr-xprojects/leptonica/build.sh15
-rw-r--r--projects/leptonica/corpus.zipbin99986 -> 0 bytes
-rw-r--r--projects/leptonica/enhance_fuzzer.cc49
-rw-r--r--projects/leptonica/pix_rotate_shear_fuzzer.cc79
-rw-r--r--projects/leptonica/pixa_recog_fuzzer.cc79
6 files changed, 10 insertions, 215 deletions
diff --git a/projects/leptonica/Dockerfile b/projects/leptonica/Dockerfile
index fd35d71a4..ccf467fd0 100644
--- a/projects/leptonica/Dockerfile
+++ b/projects/leptonica/Dockerfile
@@ -27,5 +27,4 @@ RUN git clone https://www.cl.cam.ac.uk/~mgk25/git/jbigkit jbigkit
RUN git clone --depth 1 https://github.com/libjpeg-turbo/libjpeg-turbo libjpeg-turbo
RUN git clone --depth 1 https://github.com/facebook/zstd zstd
WORKDIR leptonica
-COPY build.sh pixa_recog_fuzzer.cc enhance_fuzzer.cc \
- pix_rotate_shear_fuzzer.cc corpus.zip $SRC/
+COPY build.sh $SRC/
diff --git a/projects/leptonica/build.sh b/projects/leptonica/build.sh
index 132e65d58..4e3780015 100755
--- a/projects/leptonica/build.sh
+++ b/projects/leptonica/build.sh
@@ -106,7 +106,8 @@ make -j$(nproc)
make install
$CXX $CXXFLAGS -std=c++11 -I"$WORK/include" \
- "$SRC/pix_rotate_shear_fuzzer.cc" -o "$OUT/pix_rotate_shear_fuzzer" \
+ "$SRC/leptonica/prog/fuzzing/pix_rotate_shear_fuzzer.cc"\
+ -o "$OUT/pix_rotate_shear_fuzzer" \
"$WORK/lib/liblept.a" \
"$WORK/lib/libtiff.a" \
"$WORK/lib/libwebp.a" \
@@ -118,7 +119,8 @@ $CXX $CXXFLAGS -std=c++11 -I"$WORK/include" \
$LIB_FUZZING_ENGINE
$CXX $CXXFLAGS -std=c++11 -I"$WORK/include" \
- "$SRC/pixa_recog_fuzzer.cc" -o "$OUT/pixa_recog_fuzzer" \
+ "$SRC/leptonica/prog/fuzzing/pixa_recog_fuzzer.cc"\
+ -o "$OUT/pixa_recog_fuzzer" \
-Isrc/ \
"$WORK/lib/liblept.a" \
"$WORK/lib/libtiff.a" \
@@ -131,7 +133,8 @@ $CXX $CXXFLAGS -std=c++11 -I"$WORK/include" \
$LIB_FUZZING_ENGINE
$CXX $CXXFLAGS -std=c++11 -I"$WORK/include" \
- "$SRC/enhance_fuzzer.cc" -o "$OUT/enhance_fuzzer" \
+ "$SRC/leptonica/prog/fuzzing/enhance_fuzzer.cc"\
+ -o "$OUT/enhance_fuzzer" \
-Isrc/ \
"$WORK/lib/liblept.a" \
"$WORK/lib/libtiff.a" \
@@ -144,7 +147,7 @@ $CXX $CXXFLAGS -std=c++11 -I"$WORK/include" \
$LIB_FUZZING_ENGINE
-cp $SRC/corpus.zip /out/pix_rotate_shear_fuzzer_seed_corpus.zip
-cp $SRC/corpus.zip /out/enhance_fuzzer_seed_corpus.zip
+cp $SRC/leptonica/prog/fuzzing/general_corpus.zip $OUT/pix_rotate_shear_fuzzer_seed_corpus.zip
+cp $SRC/leptonica/prog/fuzzing/general_corpus.zip $OUT/enhance_fuzzer_seed_corpus.zip
-cd $SRC/leptonica/prog/recog/sets && zip pixa_recog_fuzzer_seed_corpus.zip test01.pa && mv pixa_recog_fuzzer_seed_corpus.zip /out/
+cp $SRC/leptonica/prog/fuzzing/pixa_recog_fuzzer_seed_corpus.zip $OUT/
diff --git a/projects/leptonica/corpus.zip b/projects/leptonica/corpus.zip
deleted file mode 100644
index 61a08f0d2..000000000
--- a/projects/leptonica/corpus.zip
+++ /dev/null
Binary files differ
diff --git a/projects/leptonica/enhance_fuzzer.cc b/projects/leptonica/enhance_fuzzer.cc
deleted file mode 100644
index 5392c24d7..000000000
--- a/projects/leptonica/enhance_fuzzer.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-# Copyright 2020 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.
-#
-################################################################################
-*/
-
-#include "string.h"
-#include "allheaders.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-
-extern "C" int
-LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
-{
- if(size<3) return 0;
- PIX *pix, *pix0, *pix1, *pix2, *pix3, *pix4;
-
- pix = pixReadMem(data, size);
- if(pix==NULL) return 0;
-
- pix0 = pixModifyHue(NULL, pix, 0.01 + 0.05 * 1);
- pix1 = pixModifySaturation(NULL, pix, -0.9 + 0.1 * 1);
- pix2 = pixMosaicColorShiftRGB(pix, -0.1, 0.0, 0.0, 0.0999, 1);
- pix3 = pixMultConstantColor(pix, 0.7, 0.4, 1.3);
- pix4 = pixUnsharpMasking(pix, 3, 0.01 + 0.15 * 1);
-
- pixDestroy(&pix);
- pixDestroy(&pix0);
- pixDestroy(&pix1);
- pixDestroy(&pix2);
- pixDestroy(&pix3);
- pixDestroy(&pix4);
- return 0;
-}
diff --git a/projects/leptonica/pix_rotate_shear_fuzzer.cc b/projects/leptonica/pix_rotate_shear_fuzzer.cc
deleted file mode 100644
index 4ca2cc90e..000000000
--- a/projects/leptonica/pix_rotate_shear_fuzzer.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-// 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.
-
-
-// The fuzzer takes as input a buffer of bytes. The buffer is read in as:
-// <angle>, <x_center>, <y_center>, and the remaining bytes will be read
-// in as a <pix>. The image is then rotated by angle around the center. All
-// inputs should not result in undefined behavior.
-#include <cmath>
-#include <cstddef>
-#include <cstdint>
-#include <cstdlib>
-#include <cstring>
-#include "leptonica/allheaders.h"
-
-// Set to true only for debugging; always false for production
-static const bool DebugOutput = false;
-
-namespace {
-
-// Reads the front bytes of a data buffer containing `size` bytes as an int16_t,
-// and advances the buffer forward [if there is sufficient capacity]. If there
-// is insufficient capacity, this returns 0 and does not modify size or data.
-int16_t ReadInt16(const uint8_t** data, size_t* size) {
- int16_t result = 0;
- if (*size >= sizeof(result)) {
- memcpy(&result, *data, sizeof(result));
- *data += sizeof(result);
- *size -= sizeof(result);
- }
- return result;
-}
-
-} // namespace
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- const int16_t angle = ReadInt16(&data, &size);
- const int16_t x_center = ReadInt16(&data, &size);
- const int16_t y_center = ReadInt16(&data, &size);
-
- // Check for pnm format; this can cause timeouts.
- // The format checker requires at least 12 bytes.
- if (size < 12) return EXIT_SUCCESS;
- int format;
- findFileFormatBuffer(data, &format);
- if (format == IFF_PNM) return EXIT_SUCCESS;
-
- Pix* pix = pixReadMem(reinterpret_cast<const unsigned char*>(data), size);
- if (pix == nullptr) {
- return EXIT_SUCCESS;
- }
-
- // Never in production
- if (DebugOutput) {
- L_INFO("w = %d, h = %d, d = %d\n", "fuzzer",
- pixGetWidth(pix), pixGetHeight(pix), pixGetDepth(pix));
- }
-
- constexpr float deg2rad = M_PI / 180.;
- Pix* pix_rotated = pixRotateShear(pix, x_center, y_center, deg2rad * angle,
- L_BRING_IN_WHITE);
- if (pix_rotated) {
- pixDestroy(&pix_rotated);
- }
-
- pixDestroy(&pix);
- return EXIT_SUCCESS;
-}
diff --git a/projects/leptonica/pixa_recog_fuzzer.cc b/projects/leptonica/pixa_recog_fuzzer.cc
deleted file mode 100644
index ae4d44ebd..000000000
--- a/projects/leptonica/pixa_recog_fuzzer.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
-# Copyright 2020 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.
-#
-################################################################################
-*/
-
-#include "string.h"
-#include "allheaders.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-
-extern "C" int
-LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
-{
- if(size<20) return 0;
-
- char filename[256];
- sprintf(filename, "/tmp/libfuzzer.pa");
-
- FILE *fp = fopen(filename, "wb");
- if (!fp)
- return 0;
- fwrite(data, size, 1, fp);
- fclose(fp);
-
- char *text;
- l_int32 histo[10];
- PIXA *pixa1, *pixa2, *pixa3, *pixa4;
- L_RECOG *recog1;
- l_int32 i, n, ival;
- PIX *pix1;
-
- pixa1 = pixaRead(filename);
- pixa2 = pixaCreate(0);
- pixa3 = pixaCreate(0);
-
- n = pixaGetCount(pixa1);
- for (i = 0; i < 10; i++)
- histo[i] = 0;
- for (i = 0; i < n; i++) {
- pix1 = pixaGetPix(pixa1, i, L_COPY);
- text = pixGetText(pix1);
- ival = text[0] - '0';
- if (ival == 4 || (ival == 7 && histo[7] == 2) ||
- (ival == 9 && histo[9] == 2)) {
- pixaAddPix(pixa3, pix1, L_INSERT);
- } else {
- pixaAddPix(pixa2, pix1, L_INSERT);
- histo[ival]++;
- }
- }
-
- recog1 = recogCreateFromPixa(pixa2, 0, 40, 1, 128, 1);
- pixa4 = recogTrainFromBoot(recog1, pixa3, 0.75, 128, 1);
-
- recogDestroy(&recog1);
- pixaDestroy(&pixa1);
- pixaDestroy(&pixa2);
- pixaDestroy(&pixa3);
- pixaDestroy(&pixa4);
- unlink(filename);
-
- return 0;
-}