Commit 51ccb12e for tesseract

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

    ccstruct: allow MergeAdjacentBlobs for words of the LSTM recognizer

    WERD_RES::MergeAdjacentBlobs() used rebuild_word without a check, but
    words from the LSTM recognizer have none. With UNLV output a page
    with a faint leader line gave such a call and a null pointer
    dereference.

    Only merge the blobs of rebuild_word if it exists. Widen the band of
    the ratings matrix in this function instead of in one of its
    callers, so that the other caller gets a valid matrix, too.

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

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

diff --git a/src/ccstruct/pageres.cpp b/src/ccstruct/pageres.cpp
index 5efe21f3..937fce43 100644
--- a/src/ccstruct/pageres.cpp
+++ b/src/ccstruct/pageres.cpp
@@ -986,10 +986,6 @@ bool WERD_RES::ConditionalBlobMerge(
       best_choice->set_unichar_id(new_id, i);
       modified = true;
       MergeAdjacentBlobs(i);
-      const MATRIX_COORD &coord = best_choice->MatrixCoord(i);
-      if (!coord.Valid(*ratings)) {
-        ratings->IncreaseBandSize(coord.row + 1 - coord.col);
-      }
       BLOB_CHOICE_LIST *blob_choices = GetBlobChoices(i);
       if (FindMatchingChoice(new_id, blob_choices) == nullptr) {
         // Insert a fake result.
@@ -1010,12 +1006,22 @@ void WERD_RES::MergeAdjacentBlobs(unsigned index) {
     reject_map.remove_pos(index);
   }
   best_choice->remove_unichar_id(index + 1);
-  rebuild_word->MergeBlobs(index, index + 2);
+  if (rebuild_word != nullptr) {
+    // Words from the LSTM recognizer have no rebuild_word.
+    rebuild_word->MergeBlobs(index, index + 2);
+  }
   box_word->MergeBoxes(index, index + 2);
   if (index + 1 < best_state.size()) {
     best_state[index] += best_state[index + 1];
     best_state.erase(best_state.begin() + index + 1);
   }
+  if (ratings != nullptr) {
+    // The merged blob may need a wider band in the ratings matrix.
+    const MATRIX_COORD &coord = best_choice->MatrixCoord(index);
+    if (!coord.Valid(*ratings)) {
+      ratings->IncreaseBandSize(coord.row + 1 - coord.col);
+    }
+  }
 }

 // TODO(tkielbus) Decide between keeping this behavior here or modifying the