Commit d41f9fee for tesseract

commit d41f9fee1db7a12c08208b0c4db63a6aec143060
Author: Stefan Weil <sw@weilnetz.de>
Date:   Fri Nov 13 17:30:19 2026 +0100

    textord: fix read out of bounds in GAPMAP for a map with one entry

    With gapmap_no_isolated_quanta the test for an isolated quantum read
    map[i + 1] for i == 0 and map[i - 1] for i == map_max without checking
    whether these neighbours exist. For a block which is narrower than one
    bucket (map_max == 0) both are outside of the array.

    Only look at neighbours which exist. The result is the same for maps
    with two or more entries. The single entry of a map with one entry is
    now always handled as isolated.

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

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

diff --git a/src/textord/gap_map.cpp b/src/textord/gap_map.cpp
index 2f460d59..59d5884a 100644
--- a/src/textord/gap_map.cpp
+++ b/src/textord/gap_map.cpp
@@ -144,11 +144,11 @@ GAPMAP::GAPMAP(     // Constructor
   }
   for (i = 0; i <= map_max; i++) {
     if (map[i] > total_rows / 2) {
-      if (gapmap_no_isolated_quanta &&
-          (((i == 0) && (map[i + 1] <= total_rows / 2)) ||
-           ((i == map_max) && (map[i - 1] <= total_rows / 2)) ||
-           ((i > 0) && (i < map_max) && (map[i - 1] <= total_rows / 2) &&
-            (map[i + 1] <= total_rows / 2)))) {
+      // Only look at neighbours which exist: the map may have a single quantum
+      // when the block is narrower than one bucket.
+      bool prev_is_gap = (i > 0) && (map[i - 1] > total_rows / 2);
+      bool next_is_gap = (i < map_max) && (map[i + 1] > total_rows / 2);
+      if (gapmap_no_isolated_quanta && !prev_is_gap && !next_is_gap) {
         map[i] = 0; // prevent isolated quantum
       } else {
         any_tabs = true;