mirror of
https://github.com/python/cpython.git
synced 2025-10-22 14:42:22 +00:00
gh-127903: Fix a crash on debug builds when calling Objects/unicodeobject::_copy_characters
` (#127876)
This commit is contained in:
parent
4c14f03495
commit
46cb6340d7
3 changed files with 15 additions and 3 deletions
|
@ -7,6 +7,7 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
|
||||||
"""
|
"""
|
||||||
import _string
|
import _string
|
||||||
import codecs
|
import codecs
|
||||||
|
import datetime
|
||||||
import itertools
|
import itertools
|
||||||
import operator
|
import operator
|
||||||
import pickle
|
import pickle
|
||||||
|
@ -1908,6 +1909,12 @@ class StrTest(string_tests.StringLikeTest,
|
||||||
self.assertRaises(UnicodeDecodeError,
|
self.assertRaises(UnicodeDecodeError,
|
||||||
(b'\xF4'+cb+b'\xBF\xBF').decode, 'utf-8')
|
(b'\xF4'+cb+b'\xBF\xBF').decode, 'utf-8')
|
||||||
|
|
||||||
|
def test_issue127903(self):
|
||||||
|
# gh-127903: ``_copy_characters`` crashes on DEBUG builds when
|
||||||
|
# there is nothing to copy.
|
||||||
|
d = datetime.datetime(2013, 11, 10, 14, 20, 59)
|
||||||
|
self.assertEqual(d.strftime('%z'), '')
|
||||||
|
|
||||||
def test_issue8271(self):
|
def test_issue8271(self):
|
||||||
# Issue #8271: during the decoding of an invalid UTF-8 byte sequence,
|
# Issue #8271: during the decoding of an invalid UTF-8 byte sequence,
|
||||||
# only the start byte and the continuation byte(s) are now considered
|
# only the start byte and the continuation byte(s) are now considered
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
``Objects/unicodeobject.c``: fix a crash on DEBUG builds in ``_copy_characters``
|
||||||
|
when there is nothing to copy.
|
|
@ -1463,11 +1463,14 @@ _copy_characters(PyObject *to, Py_ssize_t to_start,
|
||||||
assert(PyUnicode_Check(from));
|
assert(PyUnicode_Check(from));
|
||||||
assert(from_start + how_many <= PyUnicode_GET_LENGTH(from));
|
assert(from_start + how_many <= PyUnicode_GET_LENGTH(from));
|
||||||
|
|
||||||
assert(PyUnicode_Check(to));
|
assert(to == NULL || PyUnicode_Check(to));
|
||||||
assert(to_start + how_many <= PyUnicode_GET_LENGTH(to));
|
|
||||||
|
|
||||||
if (how_many == 0)
|
if (how_many == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(to != NULL);
|
||||||
|
assert(to_start + how_many <= PyUnicode_GET_LENGTH(to));
|
||||||
|
|
||||||
from_kind = PyUnicode_KIND(from);
|
from_kind = PyUnicode_KIND(from);
|
||||||
from_data = PyUnicode_DATA(from);
|
from_data = PyUnicode_DATA(from);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue