Skip to content

Commit

Permalink
Fix function Classify::WriteIntTemplates (issue tesseract-ocr#3965)
Browse files Browse the repository at this point in the history
It crashed when running mftraining because unicharset_size in file
"inttemp" was written with 8 bytes instead of 4 bytes.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Dec 11, 2022
1 parent 1d8626c commit 91920c4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/classify/intproto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,13 +919,13 @@ void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window) {
void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES_STRUCT *Templates,
const UNICHARSET &target_unicharset) {
INT_CLASS_STRUCT *Class;
auto unicharset_size = target_unicharset.size();
uint32_t unicharset_size = target_unicharset.size();
int version_id = -5; // When negated by the reader -1 becomes +1 etc.

if (Templates->NumClasses != unicharset_size) {
tprintf(
"Warning: executing WriteIntTemplates() with %d classes in"
" Templates, while target_unicharset size is %zu\n",
" Templates, while target_unicharset size is %" PRIu32 "\n",
Templates->NumClasses, unicharset_size);
}

Expand All @@ -947,6 +947,8 @@ void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES_STRUCT *Templates,
/* first write out the high level struct for the class */
fwrite(&Class->NumProtos, sizeof(Class->NumProtos), 1, File);
fwrite(&Class->NumProtoSets, sizeof(Class->NumProtoSets), 1, File);
printf("size of fontset_table_: %d, size of fontset %d: %zu (%u)\n",
fontset_table_.size(), Class->font_set_id, fontset_table_.at(Class->font_set_id).size(), Class->NumConfigs);
ASSERT_HOST(Class->NumConfigs == this->fontset_table_.at(Class->font_set_id).size());
fwrite(&Class->NumConfigs, sizeof(Class->NumConfigs), 1, File);
for (int j = 0; j < Class->NumConfigs; ++j) {
Expand Down

0 comments on commit 91920c4

Please sign in to comment.