Commit 3c3e087f for tesseract

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

    ccmain: avoid a division by zero for a page without characters

    A page can have words but no characters, when all blobs are on the
    reject lists (for example a white shape on a black page).
    rejection_passes() and doc_and_block_rejection() divided by
    page_res->char_count without a check. The tesseract executable traps
    0 / 0 when it was built with a compiler other than clang (SIGFPE).

    Test char_count > 0 first, like the code for blocks and rows does.

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

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

diff --git a/src/ccmain/control.cpp b/src/ccmain/control.cpp
index 875d7cf5..c9137bc7 100644
--- a/src/ccmain/control.cpp
+++ b/src/ccmain/control.cpp
@@ -701,21 +701,23 @@ void Tesseract::rejection_passes(PAGE_RES *page_res, ETEXT_DESC *monitor,
     page_res_it.forward();
   }

+  // A page can hold words but no characters (all blobs on the reject lists),
+  // so the ratios below must not be computed with char_count == 0.
   if (tessedit_debug_quality_metrics) {
+    const float char_count = (page_res->char_count > 0) ? page_res->char_count : 1;
     tprintf(
         "QUALITY: num_chs= %d  num_rejs= %d %5.3f blob_qual= %d %5.3f"
         " outline_errs= %d %5.3f char_qual= %d %5.3f good_ch_qual= %d %5.3f\n",
-        page_res->char_count, page_res->rej_count,
-        page_res->rej_count / static_cast<float>(page_res->char_count), stats_.doc_blob_quality,
-        stats_.doc_blob_quality / static_cast<float>(page_res->char_count), stats_.doc_outline_errs,
-        stats_.doc_outline_errs / static_cast<float>(page_res->char_count), stats_.doc_char_quality,
-        stats_.doc_char_quality / static_cast<float>(page_res->char_count),
-        stats_.doc_good_char_quality,
+        page_res->char_count, page_res->rej_count, page_res->rej_count / char_count,
+        stats_.doc_blob_quality, stats_.doc_blob_quality / char_count, stats_.doc_outline_errs,
+        stats_.doc_outline_errs / char_count, stats_.doc_char_quality,
+        stats_.doc_char_quality / char_count, stats_.doc_good_char_quality,
         (stats_.good_char_count > 0)
             ? (stats_.doc_good_char_quality / static_cast<float>(stats_.good_char_count))
             : 0.0);
   }
   bool good_quality_doc =
+      (page_res->char_count > 0) &&
       ((page_res->rej_count / static_cast<float>(page_res->char_count)) <= quality_rej_pc) &&
       (stats_.doc_blob_quality / static_cast<float>(page_res->char_count) >= quality_blob_pc) &&
       (stats_.doc_outline_errs / static_cast<float>(page_res->char_count) <= quality_outline_pc) &&
diff --git a/src/ccmain/docqual.cpp b/src/ccmain/docqual.cpp
index b1f1f1fe..1b397ce5 100644
--- a/src/ccmain/docqual.cpp
+++ b/src/ccmain/docqual.cpp
@@ -214,8 +214,9 @@ void Tesseract::doc_and_block_rejection( // reject big chunks
   int16_t char_quality = 0;
   int16_t accepted_char_quality;

-  if (page_res_it.page_res->rej_count * 100.0 / page_res_it.page_res->char_count >
-      tessedit_reject_doc_percent) {
+  if (page_res_it.page_res->char_count > 0 &&
+      page_res_it.page_res->rej_count * 100.0 / page_res_it.page_res->char_count >
+          tessedit_reject_doc_percent) {
     reject_whole_page(page_res_it);
     if (tessedit_debug_doc_rejection) {
       tprintf("REJECT ALL #chars: %d #Rejects: %d; \n", page_res_it.page_res->char_count,