Commit 32bfe595 for tesseract
commit 32bfe5958e0e52613e53c0f437999e5669689edf
Author: Stefan Weil <sw@weilnetz.de>
Date: Fri Nov 13 17:30:08 2026 +0100
wordrec: let same_point be true for equal points
The chopper relies on same_point() being true for two equal points:
near_point() uses it to refuse the insertion of a point which
coincides with the end of a segment. With chop_same_distance <= 0 the
test abs(0) < chop_same_distance fails, so vertical_projection_point()
inserted the same point again and again until the memory was used up.
Equal points are now the same for any value of chop_same_distance.
Nothing changes for values >= 1.
Fix proposed by the Anthropic OSS Scanner (finding ANT-2026-MQFM0DHQ).
Assisted-by: OpenCode / Claude Fable 5.2 (Anthropic)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
diff --git a/src/wordrec/outlines.h b/src/wordrec/outlines.h
index 1d8afef0..ec729b27 100644
--- a/src/wordrec/outlines.h
+++ b/src/wordrec/outlines.h
@@ -39,10 +39,12 @@ constexpr double MAX_ASPECT_RATIO = 2.5; /* Widest character */
* same_point
*
* Return true if the point values are the same. The parameters must
- * be of type POINT.
+ * be of type POINT. Equal points are the same for any value of
+ * chop_same_distance: the chopper relies on that to terminate.
**********************************************************************/
#define same_point(p1, p2) \
- ((abs(p1.x - p2.x) < chop_same_distance) && (abs(p1.y - p2.y) < chop_same_distance))
+ (is_equal(p1, p2) || \
+ ((abs(p1.x - p2.x) < chop_same_distance) && (abs(p1.y - p2.y) < chop_same_distance)))
/**********************************************************************
* dist_square