Commit 9d6a2471 for tesseract

commit 9d6a2471b4f918cf49b3d901d17782dd8ee363e4
Author: Stefan Weil <sw@weilnetz.de>
Date:   Fri Nov 13 21:26:23 2026 +0100

    textord: fix an endless loop in find_underlined_blobs

    The column counter was a TDimension (int16_t). It is set to the first
    column after each run of ink, which is 32767 for an underlined word
    whose last stroke is in the last column of a page with the largest
    width. The increment of the loop then wrapped the counter to -32768,
    so the scan started again and again and added the same cells to the
    list until the memory was used up.

    Use int for the counter. test_underline() has the same kind of
    counter, which was already changed for the clipping of rotated
    coordinates.

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

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

diff --git a/src/textord/underlin.cpp b/src/textord/underlin.cpp
index 37dc431b..ba981ced 100644
--- a/src/textord/underlin.cpp
+++ b/src/textord/underlin.cpp
@@ -179,7 +179,9 @@ void find_underlined_blobs(    // get chop points
                                    &middle_proj, &upper_proj);
   }

-  for (auto x = blob_box.left(); x < blob_box.right(); x++) {
+  // x must be wider than TDimension: x = y followed by x++ would otherwise
+  // wrap around and rescan the blob forever when right() is INT16_MAX.
+  for (int x = blob_box.left(); x < blob_box.right(); x++) {
     if (middle_proj.pile_count(x) > 0) {
       auto y = x + 1;
       for (; y < blob_box.right() && middle_proj.pile_count(y) > 0; y++) {