[New-bugs-announce] [issue32745] ctypes string pointer fields should accept embedded null characters
Thomas Heller
report at bugs.python.org
Thu Feb 1 14:54:50 EST 2018
New submission from Thomas Heller <theller at ctypes.org>:
ctypes Structure fields of type c_char_p or c_wchar_p used to accept strings with embedded null characters. I noticed that Python 3.6.4 does refuse them. It seems this has been changed in recent version(s).
There ARE use-cases for this: The Windows-API OPENFILENAME structure is one example. The Microsoft docs for the lpstrFilter field:
"""
lpstrFilter
Type: LPCTSTR
A buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.
"""
I have attached a simple script which demonstrates this new behaviour; the output with Python 3.6.4 is this:
Traceback (most recent call last):
File "nullchars.py", line 8, in <module>
t.unicode = u"foo\0bar"
ValueError: embedded null character
----------
components: ctypes
files: nullchars.py
keywords: 3.6regression
messages: 311462
nosy: theller
priority: normal
severity: normal
status: open
title: ctypes string pointer fields should accept embedded null characters
versions: Python 3.6
Added file: https://bugs.python.org/file47420/nullchars.py
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32745>
_______________________________________
More information about the New-bugs-announce
mailing list