From 0a365c029e437be0349c31f8d4c9926b69fa3fa1 Mon Sep 17 00:00:00 2001 From: Mihai Maruseac Date: Sat, 13 Nov 2021 10:05:59 -0800 Subject: [PATCH] Prevent null pointer dereference in constant folding. Under certain conditions, an invalid protobuf saved model with invalid nodes would be loaded. During optimization phase, Grappler optimizer will then dereference a null pointer. PiperOrigin-RevId: 409683530 Change-Id: I1f10340a7ec384bc9bc587300390f1078cf5caa0 --- tensorflow/core/grappler/optimizers/constant_folding.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tensorflow/core/grappler/optimizers/constant_folding.cc b/tensorflow/core/grappler/optimizers/constant_folding.cc index 281806be20259f..a05823f71d09f4 100644 --- a/tensorflow/core/grappler/optimizers/constant_folding.cc +++ b/tensorflow/core/grappler/optimizers/constant_folding.cc @@ -3505,6 +3505,9 @@ bool ConstantFolding::MulConvPushDown(GraphDef* optimized_graph, NodeDef* node, NodeDef* mul_left_child = node_map_->GetNode(node->input(0)); NodeDef* mul_right_child = node_map_->GetNode(node->input(1)); + if (mul_left_child == nullptr || mul_right_child == nullptr) { + return false; + } // One child must be constant, and the second must be Conv op. const bool left_child_is_constant = IsReallyConstant(*mul_left_child); const bool right_child_is_constant = IsReallyConstant(*mul_right_child);