Commit 9085e1a3 for tesseract

commit 9085e1a321504a44248d7579d33d2ecceb2d9ff0
Author: Stefan Weil <sw@weilnetz.de>
Date:   Fri Nov 13 21:26:30 2026 +0100

    ccmain: use int for offsets into the text of a word

    Several loops in reject.cpp, fixspace.cpp and docqual.cpp walk the
    UTF-8 text of a word with an int16_t byte offset or character index.
    The offset wrapped to a negative value for a word with more than
    32767 bytes, which a single line of small strokes can produce with
    the legacy engine, and the loops then read up to 32 KB in front of
    the text.

    Use int for these offsets and indices, and for the results of
    first_alphanum_index(), first_alphanum_offset() and alpha_count().

    Fix proposed by the Anthropic OSS Scanner (finding ANT-2026-GDO0O0JG).

    Assisted-by: OpenCode / Claude Fable 5.2 (Anthropic)
    Signed-off-by: Stefan Weil <sw@weilnetz.de>

diff --git a/src/ccmain/docqual.cpp b/src/ccmain/docqual.cpp
index 15e802d0..7861946f 100644
--- a/src/ccmain/docqual.cpp
+++ b/src/ccmain/docqual.cpp
@@ -63,7 +63,7 @@ int16_t Tesseract::word_outline_errs(WERD_RES *word) {
   int16_t err_count = 0;

   if (word->rebuild_word != nullptr) {
-    int16_t i = 0;
+    int i = 0;
     for (unsigned b = 0; b < word->rebuild_word->NumBlobs(); ++b) {
       TBLOB *blob = word->rebuild_word->blobs[b];
       err_count += count_outline_errs(word->best_choice->unichar_string()[i], blob->NumOutlines());
diff --git a/src/ccmain/fixspace.cpp b/src/ccmain/fixspace.cpp
index 4e122609..2bef190e 100644
--- a/src/ccmain/fixspace.cpp
+++ b/src/ccmain/fixspace.cpp
@@ -263,7 +263,7 @@ int16_t Tesseract::eval_word_spacing(WERD_RES_LIST &word_res_list) {
   int16_t word_count = 0;
   int16_t done_word_count = 0;
   int i;
-  int16_t offset;
+  int offset;
   int16_t prev_word_score = 0;
   bool prev_word_done = false;
   bool prev_char_1 = false;     // prev ch a "1/I/l"?
diff --git a/src/ccmain/reject.cpp b/src/ccmain/reject.cpp
index 6c2fc05b..36746e88 100644
--- a/src/ccmain/reject.cpp
+++ b/src/ccmain/reject.cpp
@@ -184,8 +184,8 @@ void Tesseract::make_reject_map(WERD_RES *word, int16_t pass) {
 }

 void reject_blanks(WERD_RES *word) {
-  int16_t i;
-  int16_t offset;
+  int i;
+  int offset;

   for (i = 0, offset = 0; word->best_choice->unichar_string()[offset] != '\0';
        offset += word->best_choice->unichar_lengths()[i], i += 1) {
@@ -197,8 +197,8 @@ void reject_blanks(WERD_RES *word) {
 }

 void Tesseract::reject_I_1_L(WERD_RES *word) {
-  int16_t i;
-  int16_t offset;
+  int i;
+  int offset;

   for (i = 0, offset = 0; word->best_choice->unichar_string()[offset] != '\0';
        offset += word->best_choice->unichar_lengths()[i], i += 1) {
@@ -289,11 +289,11 @@ void Tesseract::reject_edge_blobs(WERD_RES *word) {
  * - A bundle of contextual heuristics!
  **********************************************************************/
 bool Tesseract::one_ell_conflict(WERD_RES *word_res, bool update_map) {
-  int16_t word_len; // its length
-  int16_t first_alphanum_index_;
-  int16_t first_alphanum_offset_;
-  int16_t i;
-  int16_t offset;
+  int word_len; // its length
+  int first_alphanum_index_;
+  int first_alphanum_offset_;
+  int i;
+  int offset;
   bool non_conflict_set_char; // non conf set a/n?
   ACCEPTABLE_WERD_TYPE word_type;
   bool dict_perm_type;
@@ -418,7 +418,7 @@ bool Tesseract::one_ell_conflict(WERD_RES *word_res, bool update_map) {
     bool allow_1s =
         (alpha_count(word, lengths) == 0) || (word_res->best_choice->permuter() == NUMBER_PERM);

-    int16_t offset;
+    int offset;
     bool conflict = false;
     for (i = 0, offset = 0; word[offset] != '\0';
          offset += word_res->best_choice->unichar_lengths()[i++]) {
@@ -458,9 +458,9 @@ bool Tesseract::one_ell_conflict(WERD_RES *word_res, bool update_map) {
   }
 }

-int16_t Tesseract::first_alphanum_index(const char *word, const char *word_lengths) {
-  int16_t i;
-  int16_t offset;
+int Tesseract::first_alphanum_index(const char *word, const char *word_lengths) {
+  int i;
+  int offset;

   for (i = 0, offset = 0; word[offset] != '\0'; offset += word_lengths[i++]) {
     if (unicharset.get_isalpha(word + offset, word_lengths[i]) ||
@@ -471,9 +471,9 @@ int16_t Tesseract::first_alphanum_index(const char *word, const char *word_lengt
   return -1;
 }

-int16_t Tesseract::first_alphanum_offset(const char *word, const char *word_lengths) {
-  int16_t i;
-  int16_t offset;
+int Tesseract::first_alphanum_offset(const char *word, const char *word_lengths) {
+  int i;
+  int offset;

   for (i = 0, offset = 0; word[offset] != '\0'; offset += word_lengths[i++]) {
     if (unicharset.get_isalpha(word + offset, word_lengths[i]) ||
@@ -484,10 +484,10 @@ int16_t Tesseract::first_alphanum_offset(const char *word, const char *word_leng
   return -1;
 }

-int16_t Tesseract::alpha_count(const char *word, const char *word_lengths) {
-  int16_t i;
-  int16_t offset;
-  int16_t count = 0;
+int Tesseract::alpha_count(const char *word, const char *word_lengths) {
+  int i;
+  int offset;
+  int count = 0;

   for (i = 0, offset = 0; word[offset] != '\0'; offset += word_lengths[i++]) {
     if (unicharset.get_isalpha(word + offset, word_lengths[i])) {
@@ -498,8 +498,8 @@ int16_t Tesseract::alpha_count(const char *word, const char *word_lengths) {
 }

 bool Tesseract::word_contains_non_1_digit(const char *word, const char *word_lengths) {
-  int16_t i;
-  int16_t offset;
+  int i;
+  int offset;

   for (i = 0, offset = 0; word[offset] != '\0'; offset += word_lengths[i++]) {
     if (unicharset.get_isdigit(word + offset, word_lengths[i]) &&
diff --git a/src/ccmain/tesseractclass.h b/src/ccmain/tesseractclass.h
index 38ec4e1d..0735695b 100644
--- a/src/ccmain/tesseractclass.h
+++ b/src/ccmain/tesseractclass.h
@@ -581,9 +581,9 @@ public:
   // make rej map for word
   void make_reject_map(WERD_RES *word, int16_t pass);
   bool one_ell_conflict(WERD_RES *word_res, bool update_map);
-  int16_t first_alphanum_index(const char *word, const char *word_lengths);
-  int16_t first_alphanum_offset(const char *word, const char *word_lengths);
-  int16_t alpha_count(const char *word, const char *word_lengths);
+  int first_alphanum_index(const char *word, const char *word_lengths);
+  int first_alphanum_offset(const char *word, const char *word_lengths);
+  int alpha_count(const char *word, const char *word_lengths);
   bool word_contains_non_1_digit(const char *word, const char *word_lengths);
   void dont_allow_1Il(WERD_RES *word);
   int16_t count_alphanums( // how many alphanums