Commit b377f484 authored by Tony-Y's avatar Tony-Y Committed by Guolin Ke
Browse files

Bounds checking of used_row_indices (#959) (#969)

* Bounds checking of used_row_indices (#959)

* add Common::check_int32_elements_interval_closed function.

* insert a bounds checking code in LGBM_DatasetGetSubset function of C API.

* Delete a needless function

* delete the function check_int32_elements_interval_closed
parent 87fa8b54
...@@ -686,6 +686,9 @@ int LGBM_DatasetGetSubset( ...@@ -686,6 +686,9 @@ int LGBM_DatasetGetSubset(
} }
auto full_dataset = reinterpret_cast<const Dataset*>(handle); auto full_dataset = reinterpret_cast<const Dataset*>(handle);
CHECK(num_used_row_indices > 0); CHECK(num_used_row_indices > 0);
const int32_t lower = 0;
const int32_t upper = full_dataset->num_data() - 1;
Common::CheckElementsIntervalClosed(used_row_indices, lower, upper, num_used_row_indices, "Used indices of subset");
auto ret = std::unique_ptr<Dataset>(new Dataset(num_used_row_indices)); auto ret = std::unique_ptr<Dataset>(new Dataset(num_used_row_indices));
ret->CopyFeatureMapperFrom(full_dataset); ret->CopyFeatureMapperFrom(full_dataset);
ret->CopySubset(full_dataset, used_row_indices, num_used_row_indices, true); ret->CopySubset(full_dataset, used_row_indices, num_used_row_indices, true);
......
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