Skip to content

Commit

Permalink
[COMPILER][BUG] Fix out of bound access. (#1723)
Browse files Browse the repository at this point in the history
* [COMPILER][BUG] Fix out of bound access.

* 	* Review comments.
  • Loading branch information
srkreddy1238 authored and yzhliu committed Sep 18, 2018
1 parent f713aa9 commit 8c5d3ef
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions nnvm/src/top/tensor/reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ inline TShape ReduceShapeImpl(const TShape& ishape,
if (r_axes.ndim() == indim)
return TShape(keepdims ? indim : 1);

CHECK(r_axes.ndim() < indim);
if (keepdims) {
TShape oshape(ishape);
for (unsigned i = 0, j = 0; i < indim; ++i) {
if (i != r_axes[j]) continue;
if (j >= r_axes.ndim() || i != r_axes[j]) continue;
oshape[i] = 1;
++j;
}
Expand All @@ -79,7 +80,7 @@ inline TShape ReduceShapeImpl(const TShape& ishape,

TShape oshape(indim - r_axes.ndim());
for (unsigned i = 0, j = 0, k = 0; i < indim; ++i) {
if (i == r_axes[j]) {
if (j < r_axes.ndim() && i == r_axes[j]) {
++j;
continue;
}
Expand All @@ -95,7 +96,7 @@ inline bool ReduceShape(const nnvm::NodeAttrs& attrs,
CHECK_EQ(out_attrs->size(), 1U);
if ((*in_attrs)[0].ndim() == 0) return false;
const ReduceParam& param = nnvm::get<ReduceParam>(attrs.parsed);
NNVM_ASSIGN_INPUT_SHAPE(
NNVM_ASSIGN_OUTPUT_SHAPE(
attrs, *out_attrs, 0,
ReduceShapeImpl((*in_attrs)[0], param.axis,
param.keepdims, param.exclude));
Expand Down

0 comments on commit 8c5d3ef

Please sign in to comment.