Skip to content

Commit ef1d027

Browse files
Prevent copying uninitialized data in AssignOp.
This prevents harder to debug undefined behaviors that cannot be traced back to the original tensor after assignments occur earlier in the graph execution. Several of these undefined behaviors are just reference bindings to null pointers, which are caught when running under ubsan/asan. PiperOrigin-RevId: 408654780 Change-Id: Iad2ec40d43f5fd7ea016c20283356c12d5ddeab1
1 parent eeb5e21 commit ef1d027

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tensorflow/core/kernels/assign_op.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ class AssignOp : public OpKernel {
5050
// We always return the input ref.
5151
context->forward_ref_input_to_ref_output(0, 0);
5252

53+
// Prevent copying uninitialized data, to solve harder to debug undefined
54+
// behaviors that cannot be traced back to the original tensor.
55+
OP_REQUIRES(
56+
context, rhs.IsInitialized(),
57+
errors::Internal("Right hand side of AssignOp is not initialized"));
58+
5359
// We can't always know how this value will be used downstream, so make
5460
// conservative assumptions in specifying constraints on the memory
5561
// allocation attributes, unless the Grappler graph analysis determined that

0 commit comments

Comments
 (0)