Skip to content

Commit

Permalink
Improve robustness of TessdataManager
Browse files Browse the repository at this point in the history
Tesseract crashes with an unhandled exception (std::bad_alloc) if it gets
a bad tessdata file where the numEntries data field is very large (also
after swapping), for example 0x77777777.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed May 14, 2017
1 parent ffb1ec3 commit 079d6b9
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions ccutil/tessdatamanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ bool TessdataManager::LoadMemBuffer(const char *name, const char *data,
swap_ = num_entries > kMaxNumTessdataEntries || num_entries < 0;
fp.set_swap(swap_);
if (swap_) ReverseN(&num_entries, sizeof(num_entries));
if (num_entries > kMaxNumTessdataEntries || num_entries < 0) return false;
GenericVector<inT64> offset_table;
offset_table.resize_no_init(num_entries);
if (fp.FReadEndian(&offset_table[0], sizeof(offset_table[0]), num_entries) !=
Expand Down

0 comments on commit 079d6b9

Please sign in to comment.