Skip to content

Commit

Permalink
Fix heap-use-after-free in as_array()
Browse files Browse the repository at this point in the history
Array was created pointing to data in a vector, but a _copy_ of that
vector was used as the base of the array.
  • Loading branch information
jameseh96 committed May 18, 2023
1 parent ac3fa77 commit b4f8509
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pypdu/pypdu_conversion_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ void def_conversions(py::module m, py::class_<SampleSource>& cls) {
[](const SampleSource& ss,
TimestampUnits units,
bool filterNaNValues) {
auto samples = to_samples(ss);
auto samples = std::make_unique<std::vector<Sample>>();
*samples = to_samples(ss);

maybeConvertOrFilter(samples, units, filterNaNValues);
maybeConvertOrFilter(*samples, units, filterNaNValues);

return py::array_t(
samples.size(), samples.data(), py::cast(samples));
return py::array_t(samples->size(),
samples->data(),
py::cast(std::move(samples)));
},
"timestamp_units"_a = TimestampUnits::Milliseconds,
"filter_nan_values"_a = false);
Expand Down

0 comments on commit b4f8509

Please sign in to comment.