mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-98783: Fix crashes when str
subclasses are used in _PyUnicode_Equal
(#98806)
This commit is contained in:
parent
3ac8c0ab6e
commit
76f989dc3e
5 changed files with 36 additions and 3 deletions
|
@ -1334,6 +1334,12 @@ class LongTest(unittest.TestCase):
|
|||
b'\xff\xff\xff\xff\xff')
|
||||
self.assertRaises(OverflowError, (1).to_bytes, 0, 'big')
|
||||
|
||||
# gh-98783
|
||||
class SubStr(str):
|
||||
pass
|
||||
self.assertEqual((0).to_bytes(1, SubStr('big')), b'\x00')
|
||||
self.assertEqual((0).to_bytes(0, SubStr('little')), b'')
|
||||
|
||||
def test_from_bytes(self):
|
||||
def check(tests, byteorder, signed=False):
|
||||
def equivalent_python(byte_array, byteorder, signed=False):
|
||||
|
@ -1534,6 +1540,12 @@ class LongTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, int.from_bytes, MissingBytes())
|
||||
self.assertRaises(ZeroDivisionError, int.from_bytes, RaisingBytes())
|
||||
|
||||
# gh-98783
|
||||
class SubStr(str):
|
||||
pass
|
||||
self.assertEqual(int.from_bytes(b'', SubStr('big')), 0)
|
||||
self.assertEqual(int.from_bytes(b'\x00', SubStr('little')), 0)
|
||||
|
||||
@support.cpython_only
|
||||
def test_from_bytes_small(self):
|
||||
# bpo-46361
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue