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
Next Next commit
gh-146196: Fix potential Undefined Behavior in _PyUnicodeWriter_Write…
…ASCIIString
  • Loading branch information
ashm-dev committed Mar 20, 2026
commit 694c82a5fd156130679c18b9e61fa64f2a8deae5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix potential Undefined Behavior in :c:func:`PyUnicodeWriter_WriteASCII` by
adding a zero-length check and using memmove() instead of memcpy(). Patch by
Shamil Abdulaev.
Comment thread
vstinner marked this conversation as resolved.
Outdated
4 changes: 4 additions & 0 deletions Objects/unicode_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ _PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer,
if (len == -1)
len = strlen(ascii);

if (len == 0) {
return 0;
}

assert(ucs1lib_find_max_char((const Py_UCS1*)ascii, (const Py_UCS1*)ascii + len) < 128);

if (writer->buffer == NULL && !writer->overallocate) {
Expand Down
Loading