diff --git a/tensorflow/core/util/tensor_bundle/tensor_bundle.cc b/tensorflow/core/util/tensor_bundle/tensor_bundle.cc index 5c2bda4770f..dd04cea40d1 100644 --- a/tensorflow/core/util/tensor_bundle/tensor_bundle.cc +++ b/tensorflow/core/util/tensor_bundle/tensor_bundle.cc @@ -238,6 +238,23 @@ bool IsFullSlice(const TensorSlice& slice_spec, } } +Status CorruptFileError(const Status& in_status, const string& filename, + const string& detail) { + if (in_status.ok()) { + return errors::Internal("Unable to read file (", filename, + "). Perhaps the file is corrupt or was produced by " + "a newer version of TensorFlow with format changes " + "(", + detail, ")"); + } + return Status( + in_status.code(), + strings::StrCat("Unable to read file (", filename, + "). Perhaps the file is corrupt or was produced by a " + "newer version of TensorFlow with format changes (", + detail, "): ", in_status.error_message())); +} + } // namespace BundleWriter::BundleWriter(Env* env, StringPiece prefix) @@ -433,11 +450,13 @@ static Status MergeOneBundle(Env* env, StringPiece prefix, // Process header. { iter->Seek(kHeaderEntryKey); - CHECK(iter->Valid()) << "File: " << filename - << ", iterator status: " << iter->status(); + if (!iter->Valid()) { + return CorruptFileError(iter->status(), filename, + "failed to seek to header entry"); + } BundleHeaderProto header; - TF_CHECK_OK(ParseEntryProto(iter->key(), iter->value(), &header)); - CHECK_GE(header.num_shards(), 0); + Status s = ParseEntryProto(iter->key(), iter->value(), &header); + if (!s.ok()) return CorruptFileError(s, filename, "unable to parse header"); merge_state->num_shards += header.num_shards(); if (!merge_state->seen_first_bundle) { @@ -584,10 +603,17 @@ BundleReader::BundleReader(Env* env, StringPiece prefix) // Reads "num_shards_" from the first entry. iter_->Seek(kHeaderEntryKey); - CHECK(iter_->Valid()) << "File: " << filename - << ", iterator status: " << iter_->status(); + if (!iter_->Valid()) { + status_ = CorruptFileError(iter_->status(), filename, + "failed to seek to header entry"); + return; + } BundleHeaderProto header; - TF_CHECK_OK(ParseEntryProto(iter_->key(), iter_->value(), &header)); + status_ = ParseEntryProto(iter_->key(), iter_->value(), &header); + if (!status_.ok()) { + status_ = CorruptFileError(status_, filename, "unable to parse header"); + return; + } num_shards_ = header.num_shards(); if ((header.endianness() == BundleHeaderProto::BIG && port::kLittleEndian) || (header.endianness() == BundleHeaderProto::LITTLE &&