From 0fef384fb94f83abd9c787b3c8ab7abc1f7ade95 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 4 Apr 2018 11:15:56 -0700 Subject: [PATCH] Guard against out-of-bounds dims accesses, even in optimized, no-asserts builds. PiperOrigin-RevId: 191617948 --- tensorflow/contrib/lite/toco/model.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tensorflow/contrib/lite/toco/model.h b/tensorflow/contrib/lite/toco/model.h index 64269d3..9bd72e7 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()); -- 2.7.4