Skip to content

Commit 5f2f916

Browse files
committed
gh-150449: Move empty-slice validation fix to dedicated PR for gh-150913
The empty-slice assignment validation change (moving the len==0 early return to after buffer/type/size checks) has been split out to a separate bug-fix PR targeting issue #150913. This branch retains only the negative-step slice feature.
1 parent 0936d6b commit 5f2f916

2 files changed

Lines changed: 6 additions & 28 deletions

File tree

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,18 +1410,6 @@ def test_blob_set_empty_slice(self):
14101410
self.blob[0:0] = b""
14111411
self.assertEqual(self.blob[:], self.data)
14121412

1413-
def test_blob_set_empty_slice_wrong_type(self):
1414-
# Assigning a non-buffer object to an empty slice must raise TypeError
1415-
# even when the slice length is zero.
1416-
with self.assertRaises(TypeError):
1417-
self.blob[5:5] = None
1418-
1419-
def test_blob_set_empty_slice_wrong_size(self):
1420-
# Assigning a non-empty bytes object to an empty slice must raise
1421-
# IndexError because the sizes do not match.
1422-
with self.assertRaisesRegex(IndexError, "wrong size"):
1423-
self.blob[5:5] = b"123"
1424-
14251413
def test_blob_set_slice_with_skip(self):
14261414
self.blob[0:10:2] = b"12345"
14271415
actual = self.cx.execute("select b from test").fetchone()[0]
@@ -1448,9 +1436,6 @@ def test_blob_set_slice_with_negative_step(self):
14481436
state_before = bytes(self.blob[:])
14491437
self.blob[3:8:-1] = b""
14501438
self.assertEqual(bytes(self.blob[:]), state_before)
1451-
# Assigning a non-empty sequence to an empty slice must raise.
1452-
with self.assertRaisesRegex(IndexError, "wrong size"):
1453-
self.blob[3:8:-1] = b"abc"
14541439

14551440
def test_blob_mapping_invalid_index_type(self):
14561441
msg = "indices must be integers"

Modules/_sqlite/blob.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -540,31 +540,24 @@ ass_subscript_slice(pysqlite_Blob *self, PyObject *item, PyObject *value)
540540
return -1;
541541
}
542542

543+
if (len == 0) {
544+
return 0;
545+
}
546+
543547
Py_buffer vbuf;
544548
if (PyObject_GetBuffer(value, &vbuf, PyBUF_SIMPLE) < 0) {
545549
return -1;
546550
}
547551

548-
// For extended slices the right-hand side must have the exact same
549-
// element count as the slice, even when that count is zero.
552+
int rc = -1;
550553
if (vbuf.len != len) {
551554
PyErr_SetString(PyExc_IndexError,
552555
"Blob slice assignment is wrong size");
553-
PyBuffer_Release(&vbuf);
554-
return -1;
555-
}
556-
557-
if (len == 0) {
558-
PyBuffer_Release(&vbuf);
559-
return 0;
560556
}
561-
562-
int rc;
563-
if (step == 1) {
557+
else if (step == 1) {
564558
rc = inner_write(self, vbuf.buf, len, start);
565559
}
566560
else {
567-
rc = -1;
568561
// Compute the contiguous blob region covering all slice elements, then
569562
// update each element using the standard size_t-cursor pattern that
570563
// handles both positive and negative steps via unsigned arithmetic.

0 commit comments

Comments
 (0)