Skip to content

Commit fba5c90

Browse files
authored
FIX: Prevent out-of-bounds write when initializing residuals in arima… (#1073)
1 parent 3203fc5 commit fba5c90

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/arima.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cmath>
55
#include <span>
66
#include <vector>
7+
#include <stdexcept>
78

89
#include <pybind11/numpy.h>
910
#include <pybind11/pybind11.h>
@@ -136,7 +137,14 @@ arima_css(const py::array_t<double> yv, const py::array_t<int32_t> armav,
136137

137138
py::array_t<double> residv(n);
138139
const auto resid = make_span(residv);
140+
if (static_cast<size_t>(ncond) > resid.size()) {
141+
throw std::logic_error(
142+
"Internal error: resid length (" + std::to_string(resid.size()) +
143+
") must be >= ncond (" + std::to_string(ncond) + ")"
144+
);
145+
}
139146
std::fill_n(resid.begin(), ncond, 0.0);
147+
140148
std::vector<double> w(y.begin(), y.end());
141149

142150
for (size_t _ = 0; _ < d; ++_) {

0 commit comments

Comments
 (0)