Skip to content
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

[bug] Coverity fixes 2025.0 #2890

Merged
merged 6 commits into from
Sep 7, 2024
Merged

Conversation

icfaust
Copy link
Contributor

@icfaust icfaust commented Sep 4, 2024

Description

Make coverity fixes for 2025.0

Changes proposed in this pull request:

  • Remove bad bounds check from KNN classification using kdtrees

@icfaust
Copy link
Contributor Author

icfaust commented Sep 4, 2024

/intelci: run

@@ -589,7 +589,7 @@ algorithmFpType KNNClassificationTrainBatchKernel<algorithmFpType, training::def

size_t sumMid = 0;
size_t i = 0;
for (; i < sampleCount; ++i)
for (; i < __KDTREE_MEDIAN_RANDOM_SAMPLE_COUNT; ++i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

algorithmFpType samples[__KDTREE_MEDIAN_RANDOM_SAMPLE_COUNT + 1];
const size_t sampleCount = sizeof(samples) / sizeof(samples[0]);
should it be __KDTREE_MEDIAN_RANDOM_SAMPLE_COUNT + 1?

Copy link
Contributor Author

@icfaust icfaust Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, see this line https://github.com/icfaust/oneDAL/blob/dev/coverity-2025_0/cpp/daal/src/algorithms/k_nearest_neighbors/kdtree_knn_classification_train_dense_default_impl.i#L601 when this for loop terminates i == sampleCount (i.e. i == __KDTREE_MEDIAN_RANDOM_SAMPLE_COUNT + 1) so when it is used on that line, it will exceed the array bound.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, agree with you, but probably its a bug, check the line
https://github.com/oneapi-src/oneDAL/pull/2890/files#diff-e5b67a6ac7d03badd31a155779cec86abb98f260008cd311acf5166a0102b123R519
does it make sense to do the same fix here? My point that if we replace sampleCount var with __KDTREE_MEDIAN_RANDOM_SAMPLE_COUNT it makes sense to remove it everywhere, but probably its more correct to fix it as its done at the line 519

Copy link
Contributor

@avolkov-intel avolkov-intel Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about initialize sampleCount this way in this PR:
const size_t sampleCount = __KDTREE_MEDIAN_RANDOM_SAMPLE_COUNT + 1
since you are touching this part of code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Still don't understand why they had it as sizeof, I think @Alexandr-Solovev had a good theory.

@avolkov-intel
Copy link
Contributor

What I'm concerned about is that masterHist array is filled from 0 to sampleCount - 1 inclusive https://github.com/oneapi-src/oneDAL/pull/2890/files#diff-e5b67a6ac7d03badd31a155779cec86abb98f260008cd311acf5166a0102b123R580

If we apply the change from the PR the last value from masterHist array will not be used at all and seems wrong to me, so there is some mistake here. Maybe it is in the line https://github.com/oneapi-src/oneDAL/pull/2890/files#diff-e5b67a6ac7d03badd31a155779cec86abb98f260008cd311acf5166a0102b123L601 ?

@icfaust
Copy link
Contributor Author

icfaust commented Sep 6, 2024

/intelci: run

Copy link
Contributor

@avolkov-intel avolkov-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, assume CI is green

@icfaust
Copy link
Contributor Author

icfaust commented Sep 6, 2024

/intelci: run

@icfaust icfaust merged commit c56aef7 into oneapi-src:main Sep 7, 2024
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants