Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fix tf.raw_ops.ResourceCountUpTo null pointer dereference.
PiperOrigin-RevId: 368294347
Change-Id: I2c16fbfc9b4966c402c3d8e311f0d665a9c852d8
  • Loading branch information
Amit Patankar authored and tensorflower-gardener committed Apr 13, 2021
1 parent ff70c47 commit 030af76
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tensorflow/python/lib/core/ndarray_tensor.cc
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/python/lib/core/ndarray_tensor.h"

#include <cstring>
#include <optional>

#include "tensorflow/c/eager/tfe_context_internal.h"
#include "tensorflow/c/tf_tensor_internal.h"
Expand Down Expand Up @@ -74,6 +75,13 @@ Status PyArrayDescr_to_TF_DataType(PyArray_Descr* descr,
PyObject* key;
PyObject* value;
Py_ssize_t pos = 0;

// Return an error if the fields attribute is null.
// Occurs with an improper conversion attempt to resource.
if (descr->fields == nullptr) {
return errors::Internal("Unexpected numpy data type");
}

if (PyDict_Next(descr->fields, &pos, &key, &value)) {
// In Python 3, the keys of numpy custom struct types are unicode, unlike
// Python 2, where the keys are bytes.
Expand Down

0 comments on commit 030af76

Please sign in to comment.