Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit46cb634

Browse files
authored
pythongh-127903: Fix a crash on debug builds when callingObjects/unicodeobject::_copy_characters` (python#127876)
1 parent4c14f03 commit46cb634

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

‎Lib/test/test_str.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
import_string
99
importcodecs
10+
importdatetime
1011
importitertools
1112
importoperator
1213
importpickle
@@ -1908,6 +1909,12 @@ def test_utf8_decode_invalid_sequences(self):
19081909
self.assertRaises(UnicodeDecodeError,
19091910
(b'\xF4'+cb+b'\xBF\xBF').decode,'utf-8')
19101911

1912+
deftest_issue127903(self):
1913+
# gh-127903: ``_copy_characters`` crashes on DEBUG builds when
1914+
# there is nothing to copy.
1915+
d=datetime.datetime(2013,11,10,14,20,59)
1916+
self.assertEqual(d.strftime('%z'),'')
1917+
19111918
deftest_issue8271(self):
19121919
# Issue #8271: during the decoding of an invalid UTF-8 byte sequence,
19131920
# only the start byte and the continuation byte(s) are now considered
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``Objects/unicodeobject.c``: fix a crash on DEBUG builds in ``_copy_characters``
2+
when there is nothing to copy.

‎Objects/unicodeobject.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,11 +1463,14 @@ _copy_characters(PyObject *to, Py_ssize_t to_start,
14631463
assert(PyUnicode_Check(from));
14641464
assert(from_start+how_many <=PyUnicode_GET_LENGTH(from));
14651465

1466-
assert(PyUnicode_Check(to));
1467-
assert(to_start+how_many <=PyUnicode_GET_LENGTH(to));
1466+
assert(to==NULL||PyUnicode_Check(to));
14681467

1469-
if (how_many==0)
1468+
if (how_many==0) {
14701469
return0;
1470+
}
1471+
1472+
assert(to!=NULL);
1473+
assert(to_start+how_many <=PyUnicode_GET_LENGTH(to));
14711474

14721475
from_kind=PyUnicode_KIND(from);
14731476
from_data=PyUnicode_DATA(from);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp