aboutsummaryrefslogtreecommitdiff
path: root/projects/leptonica
diff options
context:
space:
mode:
authorTim King <taking@google.com>2019-10-09 10:38:51 -0700
committerMax Moroz <mmoroz@chromium.org>2019-10-09 10:38:51 -0700
commitaf03cbe9d4111fe9b43b0c532556ce88e0afd4a3 (patch)
treeac5c176298e93c51da40cf1965c6e8d5fc319981 /projects/leptonica
parent99d7bc402021a7ebee15841f296b943e6403d0b5 (diff)
downloadoss-fuzz-af03cbe9d4111fe9b43b0c532556ce88e0afd4a3.tar.gz
[leptonica] Disabling PNM format for leptonica fuzzer. (#2934)
Diffstat (limited to 'projects/leptonica')
-rw-r--r--projects/leptonica/pix_rotate_shear_fuzzer.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/projects/leptonica/pix_rotate_shear_fuzzer.cc b/projects/leptonica/pix_rotate_shear_fuzzer.cc
index 21571059d..4ca2cc90e 100644
--- a/projects/leptonica/pix_rotate_shear_fuzzer.cc
+++ b/projects/leptonica/pix_rotate_shear_fuzzer.cc
@@ -24,6 +24,9 @@
#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,
@@ -46,10 +49,24 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t 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);