From: Benoit Steiner Date: Thu, 4 Jan 2018 21:42:13 +0000 (-0800) Subject: Fixed the implementation of DataTypeString to avoid a stack overflow when X-Git-Tag: v1.6.0-rc0~304^2~5^2~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=698bc996f7190f5cd836d48d29b8c1b3ddcd37c2;p=platform%2Fupstream%2Ftensorflow.git Fixed the implementation of DataTypeString to avoid a stack overflow when processing invalid types PiperOrigin-RevId: 180839917 --- diff --git a/tensorflow/core/framework/types.cc b/tensorflow/core/framework/types.cc index 58354d6f4e..8bc4403094 100644 --- a/tensorflow/core/framework/types.cc +++ b/tensorflow/core/framework/types.cc @@ -47,11 +47,8 @@ const std::string DeviceName::value = DEVICE_GPU; const std::string DeviceName::value = DEVICE_SYCL; #endif // TENSORFLOW_USE_SYCL -string DataTypeString(DataType dtype) { - if (IsRefType(dtype)) { - DataType non_ref = static_cast(dtype - kDataTypeRefOffset); - return strings::StrCat(DataTypeString(non_ref), "_ref"); - } +namespace { +string DataTypeStringInternal(DataType dtype) { switch (dtype) { case DT_INVALID: return "INVALID"; @@ -106,6 +103,15 @@ string DataTypeString(DataType dtype) { return strings::StrCat("unknown dtype enum (", dtype, ")"); } } +} // end namespace + +string DataTypeString(DataType dtype) { + if (IsRefType(dtype)) { + DataType non_ref = static_cast(dtype - kDataTypeRefOffset); + return strings::StrCat(DataTypeStringInternal(non_ref), "_ref"); + } + return DataTypeStringInternal(dtype); +} bool DataTypeFromString(StringPiece sp, DataType* dt) { if (sp.ends_with("_ref")) {