Skip to content

Commit f76ebf7

Browse files
committed
gh-150449: Assert correctness of extreme-step slice assignment in sqlite3.Blob
Extend the existing extreme-step test cases (sys.maxsize / -sys.maxsize-1) in test_blob_set_slice_with_negative_step to verify the blob contents were actually written correctly, not just that no crash occurred.
1 parent be1aa18 commit f76ebf7

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,19 @@ def test_blob_set_slice_with_negative_step(self):
14531453
self.assertEqual(bytes(self.blob[:]), state_before)
14541454

14551455
# 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]
1456+
# Use the current blob state (already modified above) as baseline.
1457+
current = bytes(self.blob[:])
1458+
expected3 = bytearray(current)
1459+
expected3[5::sys.maxsize] = current[5::sys.maxsize]
1460+
self.blob[5::sys.maxsize] = current[5::sys.maxsize]
1461+
actual3 = self.cx.execute("select b from test").fetchone()[0]
1462+
self.assertEqual(actual3, bytes(expected3))
1463+
1464+
expected4 = bytearray(actual3)
1465+
expected4[::-sys.maxsize - 1] = bytes(actual3)[::-sys.maxsize - 1]
1466+
self.blob[::-sys.maxsize - 1] = bytes(actual3)[::-sys.maxsize - 1]
1467+
actual4 = self.cx.execute("select b from test").fetchone()[0]
1468+
self.assertEqual(actual4, bytes(expected4))
14581469

14591470
def test_blob_mapping_invalid_index_type(self):
14601471
msg = "indices must be integers"

0 commit comments

Comments
 (0)