Title: sqlite3: fix Blob.__setitem__ value range validation by ever0de · Pull Request #7981 · RustPython/RustPython · GitHub
Open Graph Title: sqlite3: fix Blob.__setitem__ value range validation by ever0de · Pull Request #7981 · RustPython/RustPython
X Title: sqlite3: fix Blob.__setitem__ value range validation by ever0de · Pull Request #7981 · RustPython/RustPython
Description: Previously, assigning an out-of-range integer (negative or > 255) or an integer too large for i64 (e.g. 2**65) to a Blob index raised OverflowError instead of ValueError.
Mirror CPython's ass_subscript_index logic:
Convert the value via to_i64(), treating any overflow as -1
Validate the result is in [0, 255], raising ValueError("byte must be in range(0, 256)") otherwise
Separate deletion error messages: "item deletion" for index, "slice deletion" for slice
Ref: https://github.com/python/cpython/blob/main/Modules/_sqlite/blob.c
Problem
When assigning an out-of-range integer to a Blob index, RustPython raised OverflowError instead of ValueError:
blob[0] = -1 # OverflowError: Python int too large to convert to Rust u8
blob[0] = 256 # OverflowError
blob[0] = 2**65 # OverflowError
CPython raises ValueError: byte must be in range(0, 256) for all three cases.
Root Cause
The previous implementation used try_to_primitive::
Open Graph Description: Previously, assigning an out-of-range integer (negative or > 255) or an integer too large for i64 (e.g. 2**65) to a Blob index raised OverflowError instead of ValueError. Mirror CPython's as...
X Description: Previously, assigning an out-of-range integer (negative or > 255) or an integer too large for i64 (e.g. 2**65) to a Blob index raised OverflowError instead of ValueError. Mirror CPython&...
Opengraph URL: https://github.com/RustPython/RustPython/pull/7981
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:33d7d8d0-6884-8b72-8988-71013f81dc1e |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A1B2:10B1AF:1482DC9:1C124EC:6A508A98 |
| html-safe-nonce | baf306106b65120b60284f1dd5cb5e0a61cf53cac7ef2b43c2e75bfe6a08451a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUIyOjEwQjFBRjoxNDgyREM5OjFDMTI0RUM6NkE1MDhBOTgiLCJ2aXNpdG9yX2lkIjoiMTg1Mjk0MzE1MDYzMDM0MTI3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ad5aa87c0460568e9b8fc3579b83699716407adaab08756578f2fc7a22b01886 |
| hovercard-subject-tag | pull_request:3745218356 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/RustPython/RustPython/pull/7981/files |
| twitter:image | https://avatars.githubusercontent.com/u/27040963?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/27040963?s=400&v=4 |
| og:image:alt | Previously, assigning an out-of-range integer (negative or > 255) or an integer too large for i64 (e.g. 2**65) to a Blob index raised OverflowError instead of ValueError. Mirror CPython's as... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7ac0ad2f2c7e4b9056617355fd9e33e22b0c8df9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width