Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ynnpack/subgraph/broadcast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ ynn_status ynn_define_broadcast(ynn_subgraph_t subgraph, size_t num_axes,

ynn::axes_set axes_set;
for (size_t i = 0; i < num_axes; ++i) {
axes_set[axis_to_slinky_dim(input.rank(), axes[i])] = true;
const int axis = axis_to_slinky_dim(input.rank(), axes[i]);
if (axis < input.rank()) {
axes_set[axis] = true;
}
}

ynn_node node;
Expand Down
3 changes: 3 additions & 0 deletions ynnpack/subgraph/copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ ynn_status ynn_define_fuse_dims(ynn_subgraph_t subgraph, size_t num_axes,
for (size_t i = 0; i < num_axes; ++i) {
YNN_RETURN_IF_ERROR(
validate_axis("fuse_dims", "input", input.rank(), axes[i]));
// Fusing requires a next dimension, so axes[i]+1 must also be valid.
YNN_RETURN_IF_ERROR(
validate_axis("fuse_dims", "input", input.rank(), axes[i] + 1));
// Since we are reversing the axes, the first dimension to fuse is actually
// the next dimension.
op.axes[axis_to_slinky_dim(input.rank(), axes[i] + 1)] = true;
Expand Down
10 changes: 10 additions & 0 deletions ynnpack/xnnpack/subgraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,11 @@ xnn_status xnn_define_static_expand_dims(xnn_subgraph_t subgraph,
const size_t* new_axes,
uint32_t input_id, uint32_t output_id,
uint32_t flags) {
if (num_new_axes > XNN_MAX_TENSOR_DIMS) {
YNN_LOG_ERROR() << "num_new_axes " << num_new_axes
<< " exceeds XNN_MAX_TENSOR_DIMS " << XNN_MAX_TENSOR_DIMS;
return xnn_status_invalid_parameter;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YNN_LOG_ERROR() << ...

}
int32_t ynn_axes[XNN_MAX_TENSOR_DIMS];
for (size_t i = 0; i < num_new_axes; ++i) {
ynn_axes[i] = new_axes[i];
Expand Down Expand Up @@ -804,6 +809,11 @@ xnn_status xnn_define_static_reduce(xnn_subgraph_t subgraph,
const size_t* reduction_axes,
uint32_t input_id, uint32_t output_id,
uint32_t flags) {
if (num_reduction_axes > XNN_MAX_TENSOR_DIMS) {
YNN_LOG_ERROR() << "num_reduction_axes " << num_reduction_axes
<< " exceeds XNN_MAX_TENSOR_DIMS " << XNN_MAX_TENSOR_DIMS;
return xnn_status_invalid_parameter;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should report an error:

YNN_LOG_ERROR() << ...

}
int64_t signed_reduction_axes[XNN_MAX_TENSOR_DIMS];
for (int i = 0; i < num_reduction_axes; i++) {
signed_reduction_axes[i] = reduction_axes[i];
Expand Down