Skip to content

Commit 694c82a

Browse files
committed
gh-146196: Fix potential Undefined Behavior in _PyUnicodeWriter_WriteASCIIString
1 parent 82a24a4 commit 694c82a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix potential Undefined Behavior in :c:func:`PyUnicodeWriter_WriteASCII` by
2+
adding a zero-length check and using memmove() instead of memcpy(). Patch by
3+
Shamil Abdulaev.

Objects/unicode_writer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ _PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer,
465465
if (len == -1)
466466
len = strlen(ascii);
467467

468+
if (len == 0) {
469+
return 0;
470+
}
471+
468472
assert(ucs1lib_find_max_char((const Py_UCS1*)ascii, (const Py_UCS1*)ascii + len) < 128);
469473

470474
if (writer->buffer == NULL && !writer->overallocate) {

0 commit comments

Comments
 (0)