Skip to content

Commit

Permalink
fix the buffer overflow problem in shape inference logic of Squeeze op
Browse files Browse the repository at this point in the history
  • Loading branch information
houseroad committed Sep 12, 2019
1 parent 797cdd0 commit 414285b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions onnx/defs/tensor/defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1265,9 +1265,16 @@ ONNX_OPERATOR_SET_SCHEMA(
ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
const auto& input_shape = ctx.getInputType(0)->tensor_type().shape();
const auto input_ndim = input_shape.dim_size();
std::transform(
axes.begin(),
axes.end(),
axes.begin(),
[&](int64_t axis) -> int64_t {
return axis < 0 ? axis + input_ndim : axis;
});

for (int i = 0, j = 0; i < input_ndim; ++i) {
auto axis_j = axes[j] < 0 ? axes[j] + input_ndim : axes[j];
if (static_cast<size_t>(j) < axes.size() && axis_j == i) {
if (std::find(axes.begin(), axes.end(), i) != axes.end()) {
if (input_shape.dim(i).has_dim_value() &&
input_shape.dim(i).dim_value() != 1) {
fail_shape_inference(
Expand Down

0 comments on commit 414285b

Please sign in to comment.