FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.13] gh-150913: Fix sqlite3.Blob validation for empty slice assignment (GH-150915) by miss-islington · Pull Request #150925 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
12 changes: 12 additions & 0 deletions Lib/test/test_sqlite3/test_dbapi.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,18 @@ def test_blob_set_empty_slice(self):
self.blob[0:0] = b""
self.assertEqual(self.blob[:], self.data)

def test_blob_set_empty_slice_wrong_type(self):
with self.assertRaises(TypeError):
self.blob[5:5] = None

def test_blob_set_empty_slice_wrong_size(self):
with self.assertRaisesRegex(IndexError, "wrong size"):
self.blob[5:5] = b"123"

def test_blob_set_empty_slice_correct(self):
self.blob[5:5] = b""
self.assertEqual(self.blob[:], self.data)

def test_blob_set_slice_with_skip(self):
self.blob[0:10:2] = b"12345"
actual = self.cx.execute("select b from test").fetchone()[0]
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :class:`sqlite3.Blob` slice assignment to raise
:exc:`TypeError` and :exc:`IndexError` for type and size mismatches
respectively, even when the target slice is empty.
16 changes: 10 additions & 6 deletions Modules/_sqlite/blob.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -517,21 +517,25 @@ ass_subscript_slice(pysqlite_Blob *self, PyObject *item, PyObject *value)
return -1;
}

if (len == 0) {
return 0;
}

Py_buffer vbuf;
if (PyObject_GetBuffer(value, &vbuf, PyBUF_SIMPLE) < 0) {
return -1;
}

int rc = -1;
if (vbuf.len != len) {
PyErr_SetString(PyExc_IndexError,
"Blob slice assignment is wrong size");
PyBuffer_Release(&vbuf);
return -1;
}
else if (step == 1) {

if (len == 0) {
PyBuffer_Release(&vbuf);
return 0;
}

int rc = -1;
if (step == 1) {
rc = inner_write(self, vbuf.buf, len, start);
}
else {
Expand Down
Loading

Back | FazBrowse Home | New Git URL