Skip to content

Commit 9e82dce

Browse files
Fix NPE in restoring code.
PiperOrigin-RevId: 388303253 Change-Id: Ia8c68568cb854bca538909a182b31a618d68ce55
1 parent e86605c commit 9e82dce

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tensorflow/core/kernels/save_restore_tensor.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,18 @@ void RestoreTensor(OpKernelContext* context,
151151
context, size == 1,
152152
errors::InvalidArgument(
153153
"Input 0 (file_pattern) must be a string scalar; got a tensor of ",
154-
size, "elements"));
154+
size, " elements"));
155155
}
156156
const string& file_pattern = file_pattern_t.flat<tstring>()(0);
157157

158158
const Tensor& tensor_name_t = context->input(1);
159+
{
160+
const int64_t size = tensor_name_t.NumElements();
161+
OP_REQUIRES(context, size > restore_index,
162+
errors::InvalidArgument(
163+
"Input 1 (file_pattern) must be a have at least ",
164+
restore_index + 1, " elements"));
165+
}
159166
const string& tensor_name = tensor_name_t.flat<tstring>()(restore_index);
160167

161168
// If we cannot find a cached reader we will allocate our own.

0 commit comments

Comments
 (0)