Skip to content

Commit 06acbaf

Browse files
committed
IntegerMatcher: Fix division by zero
Credit to OSS-Fuzz which reported this issue: intmatcher.cpp:1231:62: runtime error: division by zero #0 0x6119d5 in IntegerMatcher::ApplyCNCorrection(float, int, int, int) tesseract/src/classify/intmatcher.cpp:1231:62 #1 0x5fe9c4 in tesseract::Classify::ComputeCorrectedRating(bool, int, double, double, int, int, int, int, int, unsigned char const*) tesseract/src/classify/adaptmatch.cpp:1213:29 #2 0x5fdc22 in tesseract::Classify::ExpandShapesAndApplyCorrections(ADAPT_CLASS_STRUCT**, bool, int, int, int, float, int, int, unsigned char const*, tesseract::UnicharRating*, ADAPT_RESULTS*) tesseract/src/classify/adaptmatch.cpp:1184:13 #3 0x5fe421 in tesseract::Classify::MasterMatcher(INT_TEMPLATES_STRUCT*, short, INT_FEATURE_STRUCT const*, unsigned char const*, ADAPT_CLASS_STRUCT**, int, int, TBOX const&, GenericVector<CP_RESULT_STRUCT> const&, ADAPT_RESULTS*) tesseract/src/classify/adaptmatch.cpp:1119:5 #4 0x6003eb in tesseract::Classify::CharNormTrainingSample(bool, int, tesseract::TrainingSample const&, GenericVector<tesseract::UnicharRating>*) tesseract/src/classify/adaptmatch.cpp:1374:5 See https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13712. Signed-off-by: Stefan Weil <[email protected]>
1 parent 58423d2 commit 06acbaf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/classify/intmatcher.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ int IntegerMatcher::FindBestMatch(
12291229
float IntegerMatcher::ApplyCNCorrection(float rating, int blob_length,
12301230
int normalization_factor,
12311231
int matcher_multiplier) {
1232-
return (rating * blob_length +
1233-
matcher_multiplier * normalization_factor / 256.0) /
1234-
(blob_length + matcher_multiplier);
1232+
int divisor = blob_length + matcher_multiplier;
1233+
return divisor == 0 ? 1.0f : (rating * blob_length +
1234+
matcher_multiplier * normalization_factor / 256.0f) / divisor;
12351235
}

0 commit comments

Comments
 (0)