Skip to content

Commit 7f911ac

Browse files
committed
Fix integer overflow in overlap calculation
Signed-off-by: Stefan Weil <[email protected]>
1 parent 956525f commit 7f911ac

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/textord/colpartition.h

+6
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ class ColPartition : public ELIST2_LINK {
374374
// Returns the vertical overlap (by median) of this and other.
375375
// WARNING! Only makes sense on horizontal partitions!
376376
int VCoreOverlap(const ColPartition& other) const {
377+
if (median_bottom_ == INT32_MAX || other.median_bottom_ == INT32_MAX) {
378+
return 0;
379+
}
377380
return std::min(median_top_, other.median_top_) -
378381
std::max(median_bottom_, other.median_bottom_);
379382
}
@@ -386,6 +389,9 @@ class ColPartition : public ELIST2_LINK {
386389
// Returns true if this and other overlap significantly vertically.
387390
// WARNING! Only makes sense on horizontal partitions!
388391
bool VSignificantCoreOverlap(const ColPartition& other) const {
392+
if (median_bottom_ == INT32_MAX || other.median_bottom_ == INT32_MAX) {
393+
return false;
394+
}
389395
int overlap = VCoreOverlap(other);
390396
int height = std::min(median_top_ - median_bottom_,
391397
other.median_top_ - other.median_bottom_);

0 commit comments

Comments
 (0)