Skip to content

Commit

Permalink
Fix integer overflow in overlap calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Oct 9, 2018
1 parent 956525f commit 7f911ac
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/textord/colpartition.h
Expand Up @@ -374,6 +374,9 @@ class ColPartition : public ELIST2_LINK {
// Returns the vertical overlap (by median) of this and other.
// WARNING! Only makes sense on horizontal partitions!
int VCoreOverlap(const ColPartition& other) const {
if (median_bottom_ == INT32_MAX || other.median_bottom_ == INT32_MAX) {
return 0;
}
return std::min(median_top_, other.median_top_) -
std::max(median_bottom_, other.median_bottom_);
}
Expand All @@ -386,6 +389,9 @@ class ColPartition : public ELIST2_LINK {
// Returns true if this and other overlap significantly vertically.
// WARNING! Only makes sense on horizontal partitions!
bool VSignificantCoreOverlap(const ColPartition& other) const {
if (median_bottom_ == INT32_MAX || other.median_bottom_ == INT32_MAX) {
return false;
}
int overlap = VCoreOverlap(other);
int height = std::min(median_top_ - median_bottom_,
other.median_top_ - other.median_bottom_);
Expand Down

0 comments on commit 7f911ac

Please sign in to comment.