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
sys.setfilesystemencoding("xxx"); open("a") => stack overflow #52473
Comments
sys.setfilesystemencoding() doesn't check if the argument is a valid encoding name. If the filesystem encoding is invalid, open("a") goes into an unlimited loop. The default recursion limit is 1000, but the example crash at 930: too bad :-) Each loop allocate ~9000 bytes: Linux creates a 8 MB stack by default, and so ~9000x930 uses all the stack. Using a lower recursion limit, we can see the loop: $ ./python -c 'import sys; sys.setrecursionlimit(30); sys.setfilesystemencoding("xxx"); open("x")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 98, in search_function
level=0)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 83, in search_function
norm_encoding = normalize_encoding(encoding)
File "/home/SHARE/SVN/py3k/Lib/encodings/__init__.py", line 55, in normalize_encoding
if isinstance(encoding, bytes):
RuntimeError: maximum recursion depth exceeded while calling a Python object |
Attached patch raises a LookupError is the specified encoding is invalid. It uses _PyCodec_Lookup() function: is it allowed in bltinmodule.c? |
(duplicate of bpo-8076) |
Commited: r79393 (py3k), r79394 (3.1). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: