Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 空指针 (Null pointer) of case 17 paddle.flip #50028

Merged
merged 2 commits into from
Feb 6, 2023
Merged

Fix 空指针 (Null pointer) of case 17 paddle.flip #50028

merged 2 commits into from
Feb 6, 2023

Conversation

RedContritio
Copy link
Contributor

PR types

Bug fixes

PR changes

OPs

Describe

Solution

paddle/fluid/pybind/op_function_common.cc 中的 CastPyArg2Ints 函数里,对 PyLong_AsLong 操作的返回值进行检查,并根据 Python 文档的 PyLong_AsLong 部分,当其返回值为 -1 且 PyErr_Occurred() 不为 NULL 时,进行报错:输入值类型错误。

long PyLong_AsLong(PyObject *obj)
Part of the Stable ABI.
Return a C long representation of obj. If obj is not an instance of PyLongObject, first call its index() method (if present) to convert it to a PyLongObject.

Raise OverflowError if the value of obj is out of range for a long.

Returns -1 on error. Use PyErr_Occurred() to disambiguate.

@paddle-bot
Copy link

paddle-bot bot commented Jan 25, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels Jan 25, 2023
@RedContritio
Copy link
Contributor Author

@luotao1 辛苦更新一下,之前的解决方案有些问题,没针对底层的实际问题解决,所以关闭了原 PR 并新开了一个进行解决。

此外,paddle/fluid/pybind/op_function_common.cc 中的 CastXXX 系列方法,都缺乏对 PyXXX_AsXXXPyXXX_GetItem 等返回值的检查,有待此后优化。

比如 PySequence_GetItem 对应文档 中有提出其可能的错误情况,即返回值可能为 NULL,但代码中缺乏对应检查,导致 该空指针问题 的发生。

PyObject *PySequence_GetItem(PyObject *o, Py_ssize_t i)
Return value: New reference. Part of the Stable ABI.
Return the ith element of o, or NULL on failure. This is the equivalent of the Python expression o[i].

因此,我建议对来自 Python(库)的接口,至少在 CastXXX 系列方法中,都添加对应的返回值检查,以避免更多可能的错误情况。

为了提高 PR 的独立性,我就不继续对该文件中其他函数添加相应检查了。

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@luotao1 luotao1 merged commit d994d21 into PaddlePaddle:develop Feb 6, 2023
@RedContritio RedContritio deleted the flip branch February 13, 2023 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants