Skip to content

Commit 6e73225

Browse files
vstinnerashm-dev
andauthored
[3.14] gh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCIIString() (#146201) (#146220)
gh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCIIString() (#146201) Avoid calling memcpy(data + writer->pos, NULL, 0) which has an undefined behavior. (cherry picked from commit cd10a2e) Co-authored-by: Shamil <ashm.tech@proton.me>
1 parent 8b447fb commit 6e73225

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix potential Undefined Behavior in :c:func:`PyUnicodeWriter_WriteASCII` by
2+
adding a zero-length check. Patch by Shamil Abdulaev.

Objects/unicodeobject.c

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

14057+
if (len == 0) {
14058+
return 0;
14059+
}
14060+
1405714061
assert(ucs1lib_find_max_char((const Py_UCS1*)ascii, (const Py_UCS1*)ascii + len) < 128);
1405814062

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

0 commit comments

Comments
 (0)