tesseract  5.0.0-alpha-619-ge9db
fuzzer-api.cpp File Reference
#include <tesseract/baseapi.h>
#include "leptonica/allheaders.h"
#include <libgen.h>
#include <cstdio>
#include <cstdlib>
#include <string>

Go to the source code of this file.

Classes

class  BitReader
 

Macros

#define TESSERACT_FUZZER_WIDTH   100
 
#define TESSERACT_FUZZER_HEIGHT   100
 

Functions

int LLVMFuzzerInitialize (int *, char ***pArgv)
 
int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
 

Macro Definition Documentation

◆ TESSERACT_FUZZER_HEIGHT

#define TESSERACT_FUZZER_HEIGHT   100

Definition at line 14 of file fuzzer-api.cpp.

◆ TESSERACT_FUZZER_WIDTH

#define TESSERACT_FUZZER_WIDTH   100

Definition at line 10 of file fuzzer-api.cpp.

Function Documentation

◆ LLVMFuzzerInitialize()

int LLVMFuzzerInitialize ( int *  ,
char ***  pArgv 
)

Definition at line 47 of file fuzzer-api.cpp.

47  {
48  if (std::getenv("TESSDATA_PREFIX") == nullptr) {
49  std::string binary_path = *pArgv[0];
50  const std::string filepath = dirname(&binary_path[0]);
51 
52  const std::string tessdata_path = filepath + "/" + "tessdata";
53  if (setenv("TESSDATA_PREFIX", tessdata_path.c_str(), 1) != 0) {
54  printf("Setenv failed\n");
55  std::abort();
56  }
57  }
58 
59  api = new tesseract::TessBaseAPI();
60  if (api->Init(nullptr, "eng") != 0) {
61  printf("Cannot initialize API\n");
62  abort();
63  }
64 
65  /* Silence output */
66  api->SetVariable("debug_file", "/dev/null");
67 
68  return 0;
69 }

◆ LLVMFuzzerTestOneInput()

int LLVMFuzzerTestOneInput ( const uint8_t *  data,
size_t  size 
)

Definition at line 88 of file fuzzer-api.cpp.

88  {
89  BitReader BR(data, size);
90 
91  auto pix = createPix(BR, TESSERACT_FUZZER_WIDTH, TESSERACT_FUZZER_HEIGHT);
92 
93  api->SetImage(pix);
94 
95  char* outText = api->GetUTF8Text();
96 
97  pixDestroy(&pix);
98  delete[] outText;
99 
100  return 0;
101 }
string
std::string string
Definition: equationdetect_test.cc:21
TESSERACT_FUZZER_HEIGHT
#define TESSERACT_FUZZER_HEIGHT
Definition: fuzzer-api.cpp:14
tesseract::TessBaseAPI::Init
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_non_debug_params)
Definition: baseapi.cpp:337
tesseract::TessBaseAPI::SetVariable
bool SetVariable(const char *name, const char *value)
Definition: baseapi.cpp:277
TESSERACT_FUZZER_WIDTH
#define TESSERACT_FUZZER_WIDTH
Definition: fuzzer-api.cpp:10
BitReader
Definition: fuzzer-api.cpp:17
TessBaseAPI
struct TessBaseAPI TessBaseAPI
Definition: capi.h:72
tesseract::TessBaseAPI::GetUTF8Text
char * GetUTF8Text()
Definition: baseapi.cpp:1348
tesseract::TessBaseAPI::SetImage
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: baseapi.cpp:571