Fix segfault in has_torch_function (#88559)

Fixes #83908

`PySequence_Fast` may return `NULL` to indicate an error was raised, in which
case `sequence_has_torch_function` will dereference a null pointer.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/88559
Approved by: https://github.com/ezyang, https://github.com/Skylion007, https://github.com/hameerabbasi
This commit is contained in:
Peter Bell
2022-11-06 23:38:12 +00:00
committed by PyTorch MergeBot
parent 4796e23bbb
commit eb3f975c6e
2 changed files with 7 additions and 0 deletions

View File

@ -263,6 +263,9 @@ PyObject* THPModule_has_torch_function(PyObject*, PyObject* arg) {
} else {
auto args = py::reinterpret_steal<py::object>(
PySequence_Fast(arg, "expected a sequence"));
if (!args) {
return nullptr;
}
result = sequence_has_torch_function(args.ptr());
}