This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Disallow the null character in type name
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: florin.papa, ppperry, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2015-12-27 14:28 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
type_name_null.patch serhiy.storchaka, 2015-12-27 17:52 review
type_name_null_fix.patch florin.papa, 2015-12-31 08:46 review
Messages (7)
msg257076 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-27 14:28
The null character is allowed in __name__ setter (but error message is a little confusing).

>>> class A: pass
... 
>>> A.__name__ = 'B\0'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: __name__ must not contain null bytes

But is allowed in type constructor.

>>> t = type('B\0C', (), {})
>>> t
<class '__main__.BC'>
>>> t.__name__
'B\x00C'
msg257189 - (view) Author: (ppperry) Date: 2015-12-29 14:21
Why are null bytes being excluded from type names in the first place?
msg257191 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-29 14:39
Because tp_name is a pointer to null-terminated C string and there is no way to distinguish the name containg the null byte from the name terminated by null byte. tp_name is used for example in error messages.

>>> t = type('B\0C', (), {})
>>> t.__name__
'B\x00C'
>>> t() + 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'B' and 'int'
msg257236 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-12-30 19:42
New changeset 29cc6b2f9d28 by Serhiy Storchaka in branch '2.7':
Issue #25961: Disallowed null characters in the type name.
https://hg.python.org/cpython/rev/29cc6b2f9d28

New changeset d2417971c934 by Serhiy Storchaka in branch '3.5':
Issue #25961: Disallowed null characters in the type name.
https://hg.python.org/cpython/rev/d2417971c934

New changeset 1ab7bcd4e176 by Serhiy Storchaka in branch 'default':
Issue #25961: Disallowed null characters in the type name.
https://hg.python.org/cpython/rev/1ab7bcd4e176
msg257250 - (view) Author: Florin Papa (florin.papa) * Date: 2015-12-31 08:46
Hi all,

I fixed a compile error introduced in Python 2.7 by this issue. There is a jump made to an nonexistent label "error" in type_new function in Objects/typeobject.c. Please see the attached patch.

Regards,
Florin Papa
msg257251 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-31 10:07
Thank you Florin. How could I miss this?

But your patch is not correct. It leads to double free and deallocating using non-initialized pointer. It also contains trailing spaces and incorrect indentation.
msg257252 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-12-31 10:08
New changeset 57fea6f75ac2 by Serhiy Storchaka in branch '2.7':
Issue #25961: Fixed compilation error and a leak in type constructor.
https://hg.python.org/cpython/rev/57fea6f75ac2
History
Date User Action Args
2022-04-11 14:58:25adminsetgithub: 70149
2015-12-31 10:08:15python-devsetmessages: + msg257252
2015-12-31 10:07:29serhiy.storchakasetmessages: + msg257251
2015-12-31 08:46:27florin.papasetfiles: + type_name_null_fix.patch
nosy: + florin.papa
messages: + msg257250

2015-12-30 19:43:35serhiy.storchakasetstatus: open -> closed
assignee: serhiy.storchaka
resolution: fixed
stage: patch review -> resolved
2015-12-30 19:42:18python-devsetnosy: + python-dev
messages: + msg257236
2015-12-29 14:39:49serhiy.storchakasetmessages: + msg257191
2015-12-29 14:21:26ppperrysetnosy: + ppperry
messages: + msg257189
2015-12-27 17:52:11serhiy.storchakasetfiles: + type_name_null.patch
keywords: + patch
stage: needs patch -> patch review
2015-12-27 14:28:00serhiy.storchakacreate