mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-28 05:19:18 +08:00
Improve robustness of TessdataManager
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>
This commit is contained in:
parent
ffb1ec3535
commit
079d6b9161
@ -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) !=
|
||||
|
Loading…
Reference in New Issue
Block a user