tesseract  5.0.0
fuzzer-api.cpp File Reference
#include <allheaders.h>
#include <tesseract/baseapi.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 46 of file fuzzer-api.cpp.

46  {
47  if (std::getenv("TESSDATA_PREFIX") == nullptr) {
48  std::string binary_path = *pArgv[0];
49  const std::string filepath = dirname(&binary_path[0]);
50 
51  const std::string tessdata_path = filepath + "/" + "tessdata";
52  if (setenv("TESSDATA_PREFIX", tessdata_path.c_str(), 1) != 0) {
53  printf("Setenv failed\n");
54  std::abort();
55  }
56  }
57 
58  api = new tesseract::TessBaseAPI();
59  if (api->Init(nullptr, "eng") != 0) {
60  printf("Cannot initialize API\n");
61  abort();
62  }
63 
64  /* Silence output */
65  api->SetVariable("debug_file", "/dev/null");
66 
67  return 0;
68 }
struct TessBaseAPI TessBaseAPI
Definition: capi.h:62
bool SetVariable(const char *name, const char *value)
Definition: baseapi.cpp:276
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const std::vector< std::string > *vars_vec, const std::vector< std::string > *vars_values, bool set_only_non_debug_params)
Definition: baseapi.cpp:365

◆ LLVMFuzzerTestOneInput()

int LLVMFuzzerTestOneInput ( const uint8_t *  data,
size_t  size 
)

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

87  {
88  BitReader BR(data, size);
89 
90  auto pix = createPix(BR, TESSERACT_FUZZER_WIDTH, TESSERACT_FUZZER_HEIGHT);
91 
92  api->SetImage(pix);
93 
94  char *outText = api->GetUTF8Text();
95 
96  pixDestroy(&pix);
97  delete[] outText;
98 
99  return 0;
100 }
#define TESSERACT_FUZZER_WIDTH
Definition: fuzzer-api.cpp:10
#define TESSERACT_FUZZER_HEIGHT
Definition: fuzzer-api.cpp:14
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: baseapi.cpp:573