Skip to content

[ML] Fix potential out-of-bounds read #2385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
* Improve accuracy of anomaly detection median estimation. (See {ml-pull}2367[#2367],
issue: {ml-issue}2364[#2364].)

=== Bug Fixes

* Fix potential cause of classification and regression job failures. (See {ml-pull}2385[#2385].)

== {es} version 8.3.0

=== Enhancements
Expand Down
17 changes: 9 additions & 8 deletions lib/maths/analytics/CBoostedTreeImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1663,16 +1663,17 @@ CBoostedTreeImpl::trainTree(core::CDataFrame& frame,
this->nodeFeatureBag(treeFeatureBag, featureSampleProbabilities, nodeFeatureBag);
nodeFeatureBag = merge(featuresToInclude, std::move(nodeFeatureBag));

std::size_t numberSplittableLeaves{splittableLeaves.size()};
std::size_t currentNumberInternalNodes{(tree.size() - 1) / 2};
auto numberSplittableLeaves =
static_cast<std::ptrdiff_t>(splittableLeaves.size());
auto currentNumberInternalNodes = static_cast<std::ptrdiff_t>(tree.size() - 1) / 2;
auto lastPotentialSplit = numberSplittableLeaves + currentNumberInternalNodes -
static_cast<std::ptrdiff_t>(maximumNumberInternalNodes);
auto smallestCurrentCandidateGainIndex =
static_cast<std::ptrdiff_t>(numberSplittableLeaves) -
static_cast<std::ptrdiff_t>(maximumNumberInternalNodes - currentNumberInternalNodes);
std::min(lastPotentialSplit, numberSplittableLeaves - 1);
double smallestCandidateGain{
smallestCurrentCandidateGainIndex >= 0
? splittableLeaves[static_cast<std::size_t>(smallestCurrentCandidateGainIndex)]
->gain()
: 0.0};
smallestCurrentCandidateGainIndex < 0
? 0.0
: splittableLeaves[smallestCurrentCandidateGainIndex]->gain()};

TLeafNodeStatisticsPtr leftChild;
TLeafNodeStatisticsPtr rightChild;
Expand Down