Commit 6ce521c7 for tesseract

commit 6ce521c74844af44c7c8d8bcb5733d8a81adc10f
Author: Stefan Weil <sw@weilnetz.de>
Date:   Sun Aug 9 13:13:16 2026 +0200

    Fix CID 1487952 (Out-of-bounds access)

    Check that previous->prev is not null before accessing it in the
    while loop of ContinueContext.

    Assisted-by: OpenCode / big-pickle (opencode)
    Signed-off-by: Stefan Weil <sw@weilnetz.de>

diff --git a/src/lstm/recodebeam.cpp b/src/lstm/recodebeam.cpp
index 448d3d8b..cf20cf8d 100644
--- a/src/lstm/recodebeam.cpp
+++ b/src/lstm/recodebeam.cpp
@@ -898,6 +898,15 @@ void RecodeBeamSearch::ContinueContext(
   for (int p = length - 1; p >= 0 && previous != nullptr; --p) {
     while (previous->duplicate || previous->code == null_char_) {
       previous = previous->prev;
+      if (previous == nullptr) {
+        break;
+      }
+    }
+    if (previous == nullptr) {
+      // The beam entry has fewer than length codes in its history, so the
+      // prefix cannot be reconstructed reliably. Drop this continuation
+      // rather than using partially initialized prefix/full_code entries.
+      return;
     }
     prefix.Set(p, previous->code);
     full_code.Set(p, previous->code);