Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
methane committed Mar 15, 2019
commit 22a78c142f4a4ca32aaeb38655a913b462a5354f
4 changes: 3 additions & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,9 @@ WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored
if (len < 0) {
return -1;
}
if ((size_t)len > self->b_size/sizeof(wchar_t)) {
// PyUnicode_AsWideChar() returns number of wchars including trailing NUL,
Comment thread
methane marked this conversation as resolved.
Outdated
// when it is called with NULL.
if ((size_t)len-1 > self->b_size/sizeof(wchar_t)) {
Comment thread
methane marked this conversation as resolved.
Outdated
PyErr_SetString(PyExc_ValueError, "string too long");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth providing in the exception message the provided length and what the max length actually is?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe yes. But this file has similar codes which are not relating to wchar_t APIs. ("bytes string too long").
I want to keep this pull request simple.

result = -1;
goto done;
Expand Down
4 changes: 4 additions & 0 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,10 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
if (size < 0) {
return NULL;
}
// PyUnicode_AsWideChar() returns number of wchars including trailing NUL,
Comment thread
methane marked this conversation as resolved.
Outdated
// when it is called with NULL.
size--;
assert(size >= 0);
if (size > length) {
PyErr_Format(PyExc_ValueError,
"string too long (%zd, maximum length %zd)",
Expand Down