mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-111495: Test C API functions with extreme sizes and indices (GH-111631)
This commit is contained in:
parent
f48e669504
commit
a8e1f474c2
4 changed files with 133 additions and 39 deletions
|
@ -1,8 +1,8 @@
|
|||
import unittest
|
||||
import sys
|
||||
from test.support import import_helper
|
||||
|
||||
_testcapi = import_helper.import_module('_testcapi')
|
||||
from _testcapi import PY_SSIZE_T_MIN, PY_SSIZE_T_MAX
|
||||
|
||||
NULL = None
|
||||
|
||||
|
@ -53,10 +53,12 @@ class CAPITest(unittest.TestCase):
|
|||
self.assertEqual(fromstringandsize(b'', 0), bytearray())
|
||||
self.assertEqual(fromstringandsize(NULL, 0), bytearray())
|
||||
self.assertEqual(len(fromstringandsize(NULL, 3)), 3)
|
||||
self.assertRaises(MemoryError, fromstringandsize, NULL, sys.maxsize)
|
||||
self.assertRaises(MemoryError, fromstringandsize, NULL, PY_SSIZE_T_MAX)
|
||||
|
||||
self.assertRaises(SystemError, fromstringandsize, b'abc', -1)
|
||||
self.assertRaises(SystemError, fromstringandsize, b'abc', PY_SSIZE_T_MIN)
|
||||
self.assertRaises(SystemError, fromstringandsize, NULL, -1)
|
||||
self.assertRaises(SystemError, fromstringandsize, NULL, PY_SSIZE_T_MIN)
|
||||
|
||||
def test_fromobject(self):
|
||||
# Test PyByteArray_FromObject()
|
||||
|
@ -149,8 +151,8 @@ class CAPITest(unittest.TestCase):
|
|||
self.assertEqual(resize(ba, 3), 0)
|
||||
self.assertEqual(ba, bytearray(b'abc'))
|
||||
|
||||
self.assertRaises(MemoryError, resize, bytearray(), sys.maxsize)
|
||||
self.assertRaises(MemoryError, resize, bytearray(1000), sys.maxsize)
|
||||
self.assertRaises(MemoryError, resize, bytearray(), PY_SSIZE_T_MAX)
|
||||
self.assertRaises(MemoryError, resize, bytearray(1000), PY_SSIZE_T_MAX)
|
||||
|
||||
# CRASHES resize(bytearray(b'abc'), -1)
|
||||
# CRASHES resize(b'abc', 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue