Commit b26ceb54 for tesseract
commit b26ceb54baf08de7968e0d4ef708d974093e9870
Author: Stefan Weil <sw@weilnetz.de>
Date: Fri Nov 13 22:31:46 2026 +0100
thresholder: refuse too large images for all thresholding methods
The layout analysis keeps coordinates in TDimension (int16_t), so the
thresholder must not pass on an image with a side of more than
INT16_MAX pixels. ThresholdToPix() (thresholding method 0) checks
that, but ImageThresholder::Threshold() (methods 1 and 2) lost the
same check with commit 57b79742. With those methods a larger image
reached the line finder, where the grid of buckets in edgblob.cpp was
too small for it, and a list pointer was read and written outside of
a heap array.
Restore the check in Threshold().
Fix proposed by the Anthropic OSS Scanner (finding ANT-2026-O91ASSQK).
Assisted-by: OpenCode / Claude Fable 5.2 (Anthropic)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
diff --git a/src/ccmain/thresholder.cpp b/src/ccmain/thresholder.cpp
index 7aa142b1..200486c5 100644
--- a/src/ccmain/thresholder.cpp
+++ b/src/ccmain/thresholder.cpp
@@ -189,6 +189,13 @@ std::tuple<bool, Image, Image, Image> ImageThresholder::Threshold(
Image pix_binary = nullptr;
Image pix_thresholds = nullptr;
+ // Layout analysis stores coordinates as TDimension (int16_t), so larger
+ // images must be refused here just like in ThresholdToPix.
+ if (image_width_ > INT16_MAX || image_height_ > INT16_MAX) {
+ tprintf("Image too large: (%d, %d)\n", image_width_, image_height_);
+ return std::make_tuple(false, nullptr, nullptr, nullptr);
+ }
+
if (pix_channels_ == 0) {
// We have a binary image, but it still has to be copied, as this API
// allows the caller to modify the output.