Unverified Commit 5abf8bb9 authored by mjmckp's avatar mjmckp Committed by GitHub
Browse files

Fix access violation exception that can occur during invocation of loop lambda...


Fix access violation exception that can occur during invocation of loop lambda function when inner_start >= inner_end in 'For' template (#3936)

* Fix index out-of-range exception generated by BaggingHelper on small datasets.

Prior to this change, the line "score_t threshold = tmp_gradients[top_k - 1];" would generate an exception, since tmp_gradients would be empty when the cnt input value to the function is zero.

* Update goss.hpp

* Update goss.hpp

* Add API method LGBM_BoosterPredictForMats which runs prediction on a data set given as of array of pointers to rows (as opposed to existing method LGBM_BoosterPredictForMat which requires data given as contiguous array)

* Fix incorrect upstream merge

* Add link to LightGBM.NET

* Fix indenting to 2 spaces

* Dummy edit to trigger CI

* Dummy edit to trigger CI

* remove duplicate functions from merge

* Fix access violation exception that can occur during invocation of loop lambda function when inner_start >= inner_end in 'For' template.

In particular, this can occur in Tree::AddPredictionToScore on line 291 where the loop lambda function body (created by the PredictionFun macro) dereferences used_data_indices[start].

For reference, the particular case which triggered this exception in my case was:
  * start = 0
  * end = 93,203
  * n_block = 56
  * min_block_size = 512
for which the BlockInfo method gave:
  * n_block = 56
  * num_inner = 1,696
and so, for the case i=55 (i.e., the last case in the loop), we get
  * inner_start = start + num_inner * i
                = 93,280
which is greater than 'end' and hence triggers the exception.

* Change formatting of proposed modification
Co-authored-by: default avatarmatthew-peacock <matthew.peacock@whiteoakam.com>
Co-authored-by: default avatarGuolin Ke <guolin.ke@outlook.com>
parent 84c4b750
......@@ -78,7 +78,9 @@ class Threading {
OMP_LOOP_EX_BEGIN();
INDEX_T inner_start = start + num_inner * i;
INDEX_T inner_end = std::min(end, inner_start + num_inner);
inner_fun(i, inner_start, inner_end);
if (inner_start < inner_end) {
inner_fun(i, inner_start, inner_end);
}
OMP_LOOP_EX_END();
}
OMP_THROW_EX();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment