Commit 0c2ca00e authored by Yong Tang's avatar Yong Tang Committed by Jonathan Hseu
Browse files

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: default avatarYong Tang <yong.tang.github@outlook.com>

* Add test case for invalid type to tf.constant

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
parent 692a71da
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment