packagefs: Prevent signed integer overflow in Query::IndexGetWeightedScore.

As the comment already noted, the maximum input score is 2048,
and 2048*1024*1024 overflows int32. Subtract 1 from maxFactor
to prevent this.
This commit is contained in:
Augustin Cavalier 2021-12-08 12:26:30 -05:00
parent fb25e7349d
commit 2b4a870a7f

View File

@ -97,10 +97,9 @@ struct Query::QueryPolicy {
{
// should be inversely proportional to the index size; max input score
// is 2048
static const int32 maxFactor = 1024 * 1024;
return score * (maxFactor
/ std::min(maxFactor,
std::max((int32)1, index.index->CountEntries())));
static const int32 maxFactor = (1024 * 1024) - 1;
return score * (maxFactor /
std::min(maxFactor, std::max((int32)1, index.index->CountEntries())));
}
static type_code IndexGetType(Index& index)