From 079d6b91616094f6fcb75d174ea8e13432e06380 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 14 May 2017 21:32:26 +0200 Subject: [PATCH] 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 --- ccutil/tessdatamanager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ccutil/tessdatamanager.cpp b/ccutil/tessdatamanager.cpp index 4fb7f28a..c0bd3704 100644 --- a/ccutil/tessdatamanager.cpp +++ b/ccutil/tessdatamanager.cpp @@ -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 offset_table; offset_table.resize_no_init(num_entries); if (fp.FReadEndian(&offset_table[0], sizeof(offset_table[0]), num_entries) !=