The following issues were found

src/lstm/functions.h
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 211 Column: 3 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

              
// Copies n values of the given src vector to dest.
inline void CopyVector(int n, const TFloat *src, TFloat *dest) {
  memcpy(dest, src, n * sizeof(dest[0]));
}

// Adds n values of the given src vector to dest.
inline void AccumulateVector(int n, const TFloat *src, TFloat *dest) {
  for (int i = 0; i < n; ++i) {

            

Reported by FlawFinder.

src/lstm/network.cpp
1 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 63 Column: 8 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

              // Keep in sync with NetworkType.
// Names used in Serialization to allow re-ordering/addition/deletion of
// layer types in NetworkType without invalidating existing network files.
static char const *const kTypeNames[NT_COUNT] = {
    "Invalid",     "Input",
    "Convolve",    "Maxpool",
    "Parallel",    "Replicated",
    "ParBidiLSTM", "DepParUDLSTM",
    "Par2dLSTM",   "Series",

            

Reported by FlawFinder.

src/lstm/recodebeam.h
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 135 Column: 5 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                }
  RecodeNode &operator=(const RecodeNode &src) {
    delete dawgs;
    memcpy(this, &src, sizeof(src));
    ((RecodeNode &)src).dawgs = nullptr;
    return *this;
  }
  ~RecodeNode() {
    delete dawgs;

            

Reported by FlawFinder.

src/lstm/tfnetwork.pb.cc
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 205 Column: 5 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                } else {
    graph_ = NULL;
  }
  ::memcpy(&global_step_, &from.global_step_,
           static_cast<size_t>(reinterpret_cast<char *>(&using_ctc_) -
                               reinterpret_cast<char *>(&global_step_)) +
               sizeof(using_ctc_));
  // @@protoc_insertion_point(copy_constructor:tesseract.TFNetworkModel)
}

            

Reported by FlawFinder.

src/lstm/weightmatrix.cpp
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 171 Column: 5 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                for (int dest = 0; dest < new_no; ++dest) {
    int src = code_map[dest];
    const TFloat *src_data = src >= 0 ? old_wf[src] : means.data();
    memcpy(wf_[dest], src_data, ni * sizeof(*src_data));
  }
  return ni * new_no;
}

// Converts a float network to an int network. Each set of input weights that

            

Reported by FlawFinder.

src/textord/imagefind.cpp
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 532 Column: 5 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                  color1[COLOR_GREEN] = ClipToByte(green_stats.median());
    color1[COLOR_BLUE] = ClipToByte(blue_stats.median());
    color1[L_ALPHA_CHANNEL] = 0;
    memcpy(color2, color1, 4);
  }
  if (color_map1 != nullptr) {
    pixSetInRectArbitrary(color_map1, scaled_box,
                          ComposeRGB(color1[COLOR_RED], color1[COLOR_GREEN], color1[COLOR_BLUE]));
    pixSetInRectArbitrary(color_map2, scaled_box,

            

Reported by FlawFinder.

src/training/dawg2wordlist.cpp
1 issues
fopen - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 60 Column: 15 CWE codes: 362

              // returns 0 if successful.
static int WriteDawgAsWordlist(const UNICHARSET &unicharset, const tesseract::Dawg *dawg,
                               const char *outfile_name) {
  FILE *out = fopen(outfile_name, "wb");
  if (out == nullptr) {
    tprintf("Could not open %s for writing.\n", outfile_name);
    return 1;
  }
  WordOutputter outputter(out);

            

Reported by FlawFinder.

src/training/degradeimage.cpp
1 issues
srand - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 187 Column: 5 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

                if ((white_noise || smooth_noise) && randomizer->SignedRand(1.0) > 0.0) {
    // TODO(rays) Cook noise in a more thread-safe manner than rand().
    // Attempt to make the sequences reproducible.
    srand(randomizer->IntRand());
    Image pixn = pixAddGaussianNoise(distorted, 8.0);
    distorted.destroy();
    if (smooth_noise) {
      distorted = pixBlockconv(pixn, 1, 1);
      pixn.destroy();

            

Reported by FlawFinder.

src/training/lstmtraining.cpp
1 issues
fopen - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 96 Column: 13 CWE codes: 362

                // Check write permissions.
  std::string test_file = FLAGS_model_output.c_str();
  test_file += "_wtest";
  FILE *f = fopen(test_file.c_str(), "wb");
  if (f != nullptr) {
    fclose(f);
    if (remove(test_file.c_str()) != 0) {
      tprintf("Error, failed to remove %s: %s\n", test_file.c_str(), strerror(errno));
      return EXIT_FAILURE;

            

Reported by FlawFinder.

src/training/pango/boxchar.cpp
1 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 333 Column: 3 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

              /* static */
std::string BoxChar::GetTesseractBoxStr(int height, const std::vector<BoxChar *> &boxes) {
  std::string output;
  char buffer[kMaxLineLength];
  for (auto boxe : boxes) {
    const Box *box = boxe->box_;
    if (box == nullptr) {
      tprintf("Error: Call PrepareToWrite before WriteTesseractBoxFile!!\n");
      return "";

            

Reported by FlawFinder.