aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/lite/toco/model.h
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-04-04 11:15:56 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-04-04 11:18:50 -0700
commit0fef384fb94f83abd9c787b3c8ab7abc1f7ade95 (patch)
tree8591ef3eb5357b6b5c124615c9b71183e213edc9 /tensorflow/contrib/lite/toco/model.h
parentf4dcfcaae4e85bbb727eb1f5bfc14f6fa3a055ed (diff)
Guard against out-of-bounds dims accesses, even in optimized, no-asserts
builds. PiperOrigin-RevId: 191617948
Diffstat (limited to 'tensorflow/contrib/lite/toco/model.h')
-rw-r--r--tensorflow/contrib/lite/toco/model.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/tensorflow/contrib/lite/toco/model.h b/tensorflow/contrib/lite/toco/model.h
index 64269d369d..9bd72e7de1 100644
--- a/tensorflow/contrib/lite/toco/model.h
+++ b/tensorflow/contrib/lite/toco/model.h
@@ -1507,7 +1507,14 @@ class Shape {
// We still have that one convenience accessor to avoid
// the awkward double bracket issue: shape.dims()[i].
- int dims(int i) const { return dims_[i]; }
+ int dims(int i) const {
+ // Always check for out-of-bounds accesses, even in optimized builds where
+ // standard assertions are disabled. Out-of-bounds access here is a common
+ // occurence.
+ CHECK_GE(i, 0);
+ CHECK_GT(dims_.size(), i);
+ return dims_[i];
+ }
bool operator==(const Shape& comp) const {
return (this->dims_ == comp.dims());