Fix crash when invalid dtype was passed (#18481)
* Fix crash when invalid dtype was passed
This fix tries to address the issue raised in 18474
where crash may happen if invalid dtype (e.g., `"[,]"`)
is passed to `tf.constant(tf.string, "[,]")`. The crash
happens during the comparision of `"[,]"` and numpy dtype
candidate (e.g., `np.dtype([("qint8", np.int8, 1)])`:
```
>>> import numpy as np
>>> np.dtype([("qint8", np.int8, 1)]) == "[,]"
Segmentation fault: 11
```
This fix adds a type check to make sure the type of the passed
dtype is either numpy.dtype or type.
This fix fixes 18474.
Signed-off-by:
Yong Tang <yong.tang.github@outlook.com>
* Add test case for invalid type to tf.constant
Signed-off-by:
Yong Tang <yong.tang.github@outlook.com>
Loading
Please sign in to comment