Skip to content

Commit

Permalink
Merge pull request #51189 from tensorflow/mm-cherrypick-e0b6e58c32805…
Browse files Browse the repository at this point in the history
…9829c3eb968136f17aa72b6c876-on-r2.4

Fix segfault/heap buffer overflow in `{Experimental,}DatasetToTFRecor…
  • Loading branch information
mihaimaruseac committed Aug 5, 2021
2 parents 4ca0469 + 141dce0 commit 101764b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tensorflow/core/kernels/data/experimental/to_tf_record_op.cc
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/core/framework/function_handle_cache.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/resource_mgr.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/kernels/data/dataset_utils.h"
#include "tensorflow/core/kernels/ops_util.h"
#include "tensorflow/core/lib/core/threadpool.h"
Expand Down Expand Up @@ -87,8 +88,20 @@ class ToTFRecordOp : public AsyncOpKernel {
TF_RETURN_IF_ERROR(dataset->MakeIterator(
&iter_ctx, /*parent=*/nullptr, "ToTFRecordOpIterator", &iterator));

const int num_output_dtypes = dataset->output_dtypes().size();
if (num_output_dtypes != 1) {
return errors::InvalidArgument(
"ToTFRecordOp currently only support datasets of 1 single column, ",
"but got ", num_output_dtypes);
}
const DataType dt = dataset->output_dtypes()[0];
if (dt != DT_STRING) {
return errors::InvalidArgument(
"ToTFRecordOp currently only supports DT_STRING dataypes, but got ",
DataTypeString(dt));
}
std::vector<Tensor> components;
components.reserve(dataset->output_dtypes().size());
components.reserve(num_output_dtypes);
bool end_of_sequence;
do {
TF_RETURN_IF_ERROR(
Expand Down

0 comments on commit 101764b

Please sign in to comment.