Skip to content

Commit 0080efb

Browse files
committed
fix(axes_objects): check input bounds
1 parent 479aa71 commit 0080efb

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

source/matplot/axes_objects/contours.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,13 @@ namespace matplot {
586586
}
587587

588588
// if it increases
589+
if (Z_data_.size() < n_row + 1 || Z_data_[n_row].size() < n_col + 1 ||
590+
Z_data_.size() < opposite_row + 1 ||
591+
Z_data_[opposite_row].size() < opposite_col + 1) {
592+
// if we are outside the grid, we don't know
593+
// if it's lower or upper level
594+
return false;
595+
}
589596
bool higher_values_on_left =
590597
Z_data_[n_row][n_col] > Z_data_[opposite_row][opposite_col];
591598
if (higher_values_on_left) {

source/matplot/axes_objects/histogram.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ namespace matplot {
754754
}
755755

756756
class histogram &histogram::edge_color(std::string_view color) {
757-
edge_color(to_array(color));
757+
auto a = to_array(color);
758+
edge_color(a);
758759
return *this;
759760
}
760761

source/matplot/axes_objects/line.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ namespace matplot {
194194
size_t index =
195195
only_at_marker_indices ? marker_indices_[i] : i;
196196

197+
if (x_is_manual && index >= x_data_.size()) {
198+
break;
199+
}
197200
double x_value = x_is_manual ? x_data_[index] : index + 1;
198201
if (!std::isfinite(x_value) || !std::isfinite(y_data_[i])) {
199202
ss << " \n";

source/matplot/axes_objects/parallel_lines.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ namespace matplot {
219219

220220
const size_t n_ticks = ticks[dimension].ticks.size();
221221
constexpr double tick_size = 0.03;
222-
for (size_t i = 0; i < n_ticks + 1; ++i) {
222+
for (size_t i = 0; i < n_ticks; ++i) {
223223
double y = normalize(ticks[dimension].ticks[i], dimension);
224224
ss << " " << dimension + 1 << " " << y << "\n";
225225
const bool is_last_dimension = dimension == data_.size() - 1;

0 commit comments

Comments
 (0)