Title: sqlite3: Blob slice assignment skips validation for empty slices · Issue #150913 · python/cpython · GitHub
Open Graph Title: sqlite3: Blob slice assignment skips validation for empty slices · Issue #150913 · python/cpython
X Title: sqlite3: Blob slice assignment skips validation for empty slices · Issue #150913 · python/cpython
Description: Bug report Bug description: sqlite3.Blob slice assignment skips type and size validation when the target slice is empty (start == stop, or any slice whose computed length is zero). As a result, assignments that would normally raise TypeE...
Open Graph Description: Bug report Bug description: sqlite3.Blob slice assignment skips type and size validation when the target slice is empty (start == stop, or any slice whose computed length is zero). As a result, ass...
X Description: Bug report Bug description: sqlite3.Blob slice assignment skips type and size validation when the target slice is empty (start == stop, or any slice whose computed length is zero). As a result, ass...
Opengraph URL: https://github.com/python/cpython/issues/150913
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"sqlite3: Blob slice assignment skips validation for empty slices","articleBody":"# Bug report\n\n### Bug description:\n\n`sqlite3.Blob` slice assignment skips type and size validation when the\ntarget slice is empty (`start == stop`, or any slice whose computed\nlength is zero).\n\nAs a result, assignments that would normally raise `TypeError` or\n`IndexError` complete silently when the target slice is empty.\n\nThis behavior is inconsistent with non-empty `sqlite3.Blob` slice\nassignment and appears to be caused by an early return in\n`ass_subscript_slice()` before validation is performed.\n\n### Reproduction\n\n```python\nimport sqlite3\n\ncon = sqlite3.connect(\":memory:\")\ncon.execute(\"CREATE TABLE t(b BLOB)\")\ncon.execute(\"INSERT INTO t VALUES(zeroblob(10))\")\ncon.commit()\n\nblob = con.blobopen(\"t\", \"b\", 1)\n\n# Non-empty slice — expected behavior\nblob[0:3] = b\"12345\" # IndexError\nblob[0:3] = None # TypeError\n\n# Empty slice — BUG\nblob[5:5] = b\"123\" # silently succeeds\nblob[5:5] = None # silently succeeds\n```\n\n### Expected behavior\n\nEmpty slice assignments should be validated in the same way as non-empty\nslice assignments.\n\n```python\nblob[5:5] = b\"123\"\n```\n\nshould raise:\n\n```text\nIndexError: Blob slice assignment is wrong size\n```\n\nand\n\n```python\nblob[5:5] = None\n```\n\nshould raise:\n\n```text\nTypeError: a bytes-like object is required, not 'NoneType'\n```\n\n### Actual behavior\n\nBoth assignments complete successfully. The blob remains unchanged and\nno exception is raised.\n\n### Root cause\n\nIn `Modules/_sqlite/blob.c`, `ass_subscript_slice()` returns early when\nthe computed slice length is zero.\n\nBecause this early return occurs before the bytes-like object check and\nslice-size validation, invalid assignments are silently accepted for\nempty slices.\n\n### Related\n\nDiscovered during review of #150450 (negative-step slice handling for\n`sqlite3.Blob`).\n\nReview discussion:\n\nhttps://github.com/python/cpython/pull/150450#discussion_r3326381267\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-150915\n* gh-150923\n* gh-150924\n* gh-150925\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ever0de","@type":"Person","name":"ever0de"},"datePublished":"2026-06-04T12:16:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/150913/cpython/issues/150913"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d04cd97b-959c-d16c-7932-6b969f64f67a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DFEE:1F40D1:4B368C:680D8A:6A51214E |
| html-safe-nonce | f7acdc7098aec212f4b34b8711b71c2e6110d96ac018899f4033df5ef14d4a28 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkVFOjFGNDBEMTo0QjM2OEM6NjgwRDhBOjZBNTEyMTRFIiwidmlzaXRvcl9pZCI6IjEzNjAxNzUwNTg3Njk3NDgzMDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6a06f0ac0683ec284b76002bb4b8cd20dd1bbc327dd28f06e8381168088bd10a |
| hovercard-subject-tag | issue:4588599359 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/150913/issue_layout |
| twitter:image | https://opengraph.githubassets.com/969f3ee9304ecb5a9cef438f40477351fea9857ebccd9288bec59ac3a00bc24f/python/cpython/issues/150913 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/969f3ee9304ecb5a9cef438f40477351fea9857ebccd9288bec59ac3a00bc24f/python/cpython/issues/150913 |
| og:image:alt | Bug report Bug description: sqlite3.Blob slice assignment skips type and size validation when the target slice is empty (start == stop, or any slice whose computed length is zero). As a result, ass... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ever0de |
| hostname | github.com |
| expected-hostname | github.com |
| None | 689b683944b0d7f015d0e776452c970832fa81b82dc15284469b556ecced715b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 942b51ed3bd5feee3d5e2719f890a5fe286edbbb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width