Commit b998a91e for tesseract

commit b998a91efc733718846137227e4cad89d21764d6
Author: Stefan Weil <sw@weilnetz.de>
Date:   Fri Nov 13 22:31:46 2026 +0100

    ccmain: fix an endless loop in the fuzzy space code

    The search loops in fix_fuzzy_space_list() and fix_noisy_space_list()
    expect that each score other than PERFECT_WERDS is lower than that
    value: they only stop for it or for an empty list, and only go on to
    the next permutation for a lower score. PERFECT_WERDS was 999, but
    eval_word_spacing() returns a count of characters without a limit.
    A run of about 1000 characters with fuzzy spaces got a higher score,
    and the loop neither stopped nor went on.

    Use INT16_MAX for PERFECT_WERDS, and limit the other scores to less
    than that.

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

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

diff --git a/src/ccmain/fixspace.cpp b/src/ccmain/fixspace.cpp
index 31e2b00a..be74a409 100644
--- a/src/ccmain/fixspace.cpp
+++ b/src/ccmain/fixspace.cpp
@@ -38,14 +38,17 @@
 #include <tesseract/ocrclass.h> // for ETEXT_DESC
 #include <tesseract/unichar.h>  // for UNICHAR_ID

-#include <cstdint> // for INT16_MAX, int16_t, int32_t
+#include <algorithm> // for std::min
+#include <cstdint>   // for INT16_MAX, int16_t, int32_t

 namespace tesseract {

 class BLOCK;
 class ROW;

-#define PERFECT_WERDS 999
+// Score of a word list in which all words are contextually confirmed.
+// It must be greater than any score which is a count of characters.
+#define PERFECT_WERDS INT16_MAX

 /**********************************************************************
  *  c_blob_comparator()
@@ -259,7 +262,7 @@ void Tesseract::match_current_words(WERD_RES_LIST &words, ROW *row, BLOCK *block
  */
 int16_t Tesseract::eval_word_spacing(WERD_RES_LIST &word_res_list) {
   WERD_RES_IT word_res_it(&word_res_list);
-  int16_t total_score = 0;
+  int total_score = 0;
   int16_t word_count = 0;
   int16_t done_word_count = 0;
   int i;
@@ -358,7 +361,7 @@ int16_t Tesseract::eval_word_spacing(WERD_RES_LIST &word_res_list) {
   if (done_word_count == word_count) {
     return PERFECT_WERDS;
   } else {
-    return total_score;
+    return std::min(total_score, PERFECT_WERDS - 1);
   }
 }