Skip to content

Commit

Permalink
FIX potential integer overflow (#2478)
Browse files Browse the repository at this point in the history
* cast to uint64_t to avoid overflow

* Update cpp/daal/src/algorithms/dtrees/gbt/gbt_train_tree_builder.i

Co-authored-by: Samir Nasibli <samir.nasibli@intel.com>

---------

Co-authored-by: Dmitry Razdoburdin <>
Co-authored-by: Samir Nasibli <samir.nasibli@intel.com>
  • Loading branch information
razdoburdin and samir-nasibli authored Aug 31, 2023
1 parent f6f0cc9 commit b864740
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cpp/daal/src/algorithms/dtrees/gbt/gbt_train_tree_builder.i
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ bool TreeBuilder<algorithmFPType, RowIndexType, BinIndexType, cpu>::initMemHelpe
const auto nFeat = _ctx.nFeatures();
if (nFeat != _ctx.nFeaturesPerNode())
{
if (_ctx.nFeaturesPerNode() * _ctx.nFeaturesPerNode() < 2 * nFeat)
// cast to 64-bits uint to avoid potential overflow
const auto nFeaturesPerNode = static_cast<uint64_t>(_ctx.nFeaturesPerNode());
if (nFeaturesPerNode * nFeaturesPerNode < 2 * nFeat)
featuresSampleBufSize = 2 * _ctx.nFeaturesPerNode();
else
featuresSampleBufSize = nFeat;
Expand Down

0 comments on commit b864740

Please sign in to comment.