Skip to content

_PyModule_IsPossiblyShadowing can return -1 without an exception set #130932

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

Closed
colesbury opened this issue Mar 6, 2025 · 1 comment
Closed
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@colesbury
Copy link
Contributor

colesbury commented Mar 6, 2025

Bug report

Bug description:

This can lead to an assertion failure:

#6  0x00007ffff7ca9e96 in __GI___assert_fail (assertion=0x555555a5e2da "PyErr_Occurred()", file=0x555555a6edcd "Objects/object.c", line=1253, function=0x555555a6f36e "int _PyObject_SetAttributeErrorContext(PyObject *, PyObject *)") at ./assert/assert.c:101
#7  0x00005555557273ac in _PyObject_SetAttributeErrorContext (v=<module at remote 0x200009a1a50>, name='getaliases') at Objects/object.c:1253
#8  0x0000555555726dde in PyObject_GetAttr (v=<module at remote 0x200009a1a50>, name='getaliases') at Objects/object.c:1306
#9  0x0000555555727de6 in _PyObject_GetMethod (obj=<module at remote 0x200009a1a50>, name='getaliases', method=0x7ffffffdb1b8) at Objects/object.c:1581
#10 0x000055555588456d in _PyEval_EvalFrameDefault (tstate=0x555555d16fb0 <_PyRuntime+360560>, frame=0x7ffff7f9cf20, throwflag=0) at Python/generated_cases.c.h:7682

_Py_wgetcwd does not set an exception on failure:

if (!_Py_wgetcwd(sys_path_0_buf, MAXPATHLEN)) {
return -1;

Likely related to #95754

cc @hauntsaninja

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

@colesbury colesbury added the type-bug An unexpected behavior, bug, or error label Mar 6, 2025
@hauntsaninja
Copy link
Contributor

Thanks for spotting! Will put a PR...

hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue Mar 6, 2025
…iblyShadowing

I chose to not raise an exception here because I think it would be
confusing for module attribute access to start raising something other
than AttributeError if e.g. the cwd goes away

Without the change in moduleobject.c
```
./python.exe -m unittest test.test_import.ImportTests.test_script_shadowing_stdlib_cwd_failure
...
Assertion failed: (PyErr_Occurred()), function _PyObject_SetAttributeErrorContext, file object.c, line 1253.
```
hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue Mar 7, 2025
@picnixz picnixz added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Mar 7, 2025
hauntsaninja added a commit that referenced this issue Mar 7, 2025
…adowing (#130934)

I chose to not raise an exception here because I think it would be
confusing for module attribute access to start raising something other
than AttributeError if e.g. the cwd goes away

Without the change in moduleobject.c
```
./python.exe -m unittest test.test_import.ImportTests.test_script_shadowing_stdlib_cwd_failure
...
Assertion failed: (PyErr_Occurred()), function _PyObject_SetAttributeErrorContext, file object.c, line 1253.
```
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 7, 2025
…iblyShadowing (pythonGH-130934)

I chose to not raise an exception here because I think it would be
confusing for module attribute access to start raising something other
than AttributeError if e.g. the cwd goes away

Without the change in moduleobject.c
```
./python.exe -m unittest test.test_import.ImportTests.test_script_shadowing_stdlib_cwd_failure
...
Assertion failed: (PyErr_Occurred()), function _PyObject_SetAttributeErrorContext, file object.c, line 1253.
```
(cherry picked from commit 0a9ae5e)

Co-authored-by: Shantanu <[email protected]>
hauntsaninja added a commit that referenced this issue Mar 7, 2025
…siblyShadowing (GH-130934) (#130939)

gh-130932: Fix incorrect exception handling in _PyModule_IsPossiblyShadowing (GH-130934)

I chose to not raise an exception here because I think it would be
confusing for module attribute access to start raising something other
than AttributeError if e.g. the cwd goes away

Without the change in moduleobject.c
```
./python.exe -m unittest test.test_import.ImportTests.test_script_shadowing_stdlib_cwd_failure
...
Assertion failed: (PyErr_Occurred()), function _PyObject_SetAttributeErrorContext, file object.c, line 1253.
```
(cherry picked from commit 0a9ae5e)

Co-authored-by: Shantanu <[email protected]>
@sobolevn sobolevn closed this as completed Mar 7, 2025
kulikjak added a commit to kulikjak/cpython that referenced this issue Mar 10, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 11, 2025
vstinner pushed a commit that referenced this issue Mar 11, 2025
#131073)

gh-130932: cwd cannot be removed on Solaris/Illumos (GH-131037)
(cherry picked from commit 69309a5)

Co-authored-by: Jakub Kulík <[email protected]>
@picnixz picnixz added 3.13 bugs and security fixes 3.14 bugs and security fixes labels Mar 12, 2025
seehwan pushed a commit to seehwan/cpython that referenced this issue Apr 16, 2025
…iblyShadowing (python#130934)

I chose to not raise an exception here because I think it would be
confusing for module attribute access to start raising something other
than AttributeError if e.g. the cwd goes away

Without the change in moduleobject.c
```
./python.exe -m unittest test.test_import.ImportTests.test_script_shadowing_stdlib_cwd_failure
...
Assertion failed: (PyErr_Occurred()), function _PyObject_SetAttributeErrorContext, file object.c, line 1253.
```
seehwan pushed a commit to seehwan/cpython that referenced this issue Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants