diff --git a/cpp/src/arrow/extension/fixed_shape_tensor.cc b/cpp/src/arrow/extension/fixed_shape_tensor.cc index 15e6f8d731fcd..94af57689da9c 100644 --- a/cpp/src/arrow/extension/fixed_shape_tensor.cc +++ b/cpp/src/arrow/extension/fixed_shape_tensor.cc @@ -392,6 +392,12 @@ Result> FixedShapeTensorType::Make( return Status::Invalid("dim_names size must match shape size. Expected: ", shape.size(), " Got: ", dim_names.size()); } + for (auto i : permutation) { + if (i < 0 || i >= static_cast(shape.size())) { + return Status::Invalid("permutation indices must be in [0, shape.size()). Got: ", + i); + } + } const auto size = std::accumulate(shape.begin(), shape.end(), static_cast(1), std::multiplies<>()); return std::make_shared(value_type, static_cast(size),