Hi I'm adding array bounds check in nnvm/Tuple:
commit 87eee62cce5dda325f8a66447b6746a1cc1ed90b (HEAD -> mxnet) Author: Pedro Larroy <[email protected]> Date: Tue Oct 24 02:59:46 2017 +0200 Check array bounds in tuple in operator[] diff --git a/include/nnvm/tuple.h b/include/nnvm/tuple.h index f613858..420f1f7 100644 --- a/include/nnvm/tuple.h +++ b/include/nnvm/tuple.h @@ -160,6 +160,7 @@ class Tuple { * \return the corresponding dimension size */ inline ValueType& operator[](size_t i) { + CHECK_LT(i, ndim_) << "tuple index out of bounds"; return begin()[i]; } /*! @@ -168,6 +169,7 @@ class Tuple { * \return the corresponding dimension size */ inline const ValueType& operator[](size_t i) const { + CHECK_LT(i, ndim_) << "tuple index out of bounds"; return begin()[i]; } /*! And fixing places where we access out of bounds, even if it's correct, for example chaging access &tuple[end] to tuple.end() so indexed access will always be bound checked. For example: - R[0] = mshadow::Shape1(rshape[0]); - R[1] = rshape.ndim() > 1 ? TShape(&rshape[1], &rshape[rshape.ndim()]) : TShape(1); + R[0] = mshadow::Shape1(*rshape.begin()); + R[1] = rshape.ndim() > 1 ? TShape(rshape.begin()+1, rshape.end()) : TShape(1); Any inconvenients in regards to this approach? Pedro.
