Skip to content

Commit be1aa18

Browse files
committed
gh-150449: Add tests for extreme step values in sqlite3.Blob slice operations
Add test cases for sys.maxsize and -sys.maxsize-1 step values in both read (test_blob_get_slice_with_negative_step) and write (test_blob_set_slice_with_negative_step) to cover the unsigned wrap-around arithmetic path that avoids signed integer overflow.
1 parent d47abf8 commit be1aa18

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,9 @@ def test_blob_get_slice_with_negative_step(self):
13991399
# must return b"" rather than crashing or raising an exception.
14001400
self.assertEqual(self.blob[3:8:-1], self.data[3:8:-1]) # b""
14011401
self.assertEqual(self.blob[5:5:-1], self.data[5:5:-1]) # b""
1402+
# Extreme step values: cur += (size_t)step must not overflow.
1403+
self.assertEqual(self.blob[5::sys.maxsize], self.data[5::sys.maxsize])
1404+
self.assertEqual(self.blob[::-sys.maxsize - 1], self.data[::-sys.maxsize - 1])
14021405

14031406
def test_blob_set_slice(self):
14041407
self.blob[0:5] = b"12345"
@@ -1449,6 +1452,10 @@ def test_blob_set_slice_with_negative_step(self):
14491452
self.blob[3:8:-1] = b""
14501453
self.assertEqual(bytes(self.blob[:]), state_before)
14511454

1455+
# Extreme step values: cur += (size_t)step must not overflow.
1456+
self.blob[5::sys.maxsize] = self.data[5::sys.maxsize]
1457+
self.blob[::-sys.maxsize - 1] = self.data[::-sys.maxsize - 1]
1458+
14521459
def test_blob_mapping_invalid_index_type(self):
14531460
msg = "indices must be integers"
14541461
with self.assertRaisesRegex(TypeError, msg):

0 commit comments

Comments
 (0)