Title: Possible UB in bytes_characters · Issue #106693 · python/cpython · GitHub
Open Graph Title: Possible UB in bytes_characters · Issue #106693 · python/cpython
X Title: Possible UB in bytes_characters · Issue #106693 · python/cpython
Description: in bytes_characters in https://github.com/python/cpython/blob/main/Include/internal/pycore_runtime_init.h we are doing this: .bytes_characters = _Py_bytes_characters_INIT, \ where #define _Py_bytes_characters_INIT { \ _PyBytes_CHAR_INIT(...
Open Graph Description: in bytes_characters in https://github.com/python/cpython/blob/main/Include/internal/pycore_runtime_init.h we are doing this: .bytes_characters = _Py_bytes_characters_INIT, \ where #define _Py_bytes...
X Description: in bytes_characters in https://github.com/python/cpython/blob/main/Include/internal/pycore_runtime_init.h we are doing this: .bytes_characters = _Py_bytes_characters_INIT, \ where #define _Py_bytes...
Opengraph URL: https://github.com/python/cpython/issues/106693
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Possible UB in bytes_characters","articleBody":"in `bytes_characters` in https://github.com/python/cpython/blob/main/Include/internal/pycore_runtime_init.h we are doing this:\r\n\r\n```\r\n.bytes_characters = _Py_bytes_characters_INIT, \\\r\n```\r\n\r\nwhere\r\n\r\n```\r\n#define _Py_bytes_characters_INIT { \\\r\n _PyBytes_CHAR_INIT(0), \\\r\n _PyBytes_CHAR_INIT(1), \\\r\n _PyBytes_CHAR_INIT(2), \\\r\n _PyBytes_CHAR_INIT(3), \\\r\n _PyBytes_CHAR_INIT(4), \\\r\n _PyBytes_CHAR_INIT(5), \\\r\n _PyBytes_CHAR_INIT(6), \\\r\n _PyBytes_CHAR_INIT(7), \\\r\n _PyBytes_CHAR_INIT(8), \\\r\n _PyBytes_CHAR_INIT(9), \\\r\n...\r\n _PyBytes_CHAR_INIT(255), \\\r\n```\r\n\r\nwith\r\n\r\n```\r\n#define _PyBytes_CHAR_INIT(CH) \\\r\n { \\\r\n _PyBytes_SIMPLE_INIT((CH), 1) \\\r\n }\r\n\r\n#define _PyBytes_SIMPLE_INIT(CH, LEN) \\\r\n { \\\r\n _PyVarObject_HEAD_INIT(&PyBytes_Type, (LEN)) \\\r\n .ob_shash = -1, \\\r\n .ob_sval = { (CH) }, \\\r\n }\r\n```\r\n\r\nbut\r\n\r\nhttps://github.com/python/cpython/blob/e4b88c1e4ac129b36f99a534387d64f7b8cda8ef/Include/internal/pycore_global_objects.h#L41-L44\r\n\r\nand\r\n\r\nhttps://github.com/python/cpython/blob/e4b88c1e4ac129b36f99a534387d64f7b8cda8ef/Include/cpython/bytesobject.h#L5-L15\r\n\r\nI think this is UB because when we are basically assigning 255 to:\r\n\r\nhttps://github.com/python/cpython/blob/e4b88c1e4ac129b36f99a534387d64f7b8cda8ef/Include/cpython/bytesobject.h#L8C10-L8C17\r\n\r\nand that should be a `unsigned char` because the range of `char` can be 0 to 255 or -128 to 127 depending on the platform.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-106826\n* gh-149510\n* gh-149511\n* gh-149514\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/pablogsal","@type":"Person","name":"pablogsal"},"datePublished":"2023-07-12T20:36:07Z","url":"https://github.com/python/cpython/issues/106693"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:99fd2700-aeb9-fb72-7a19-afb17ba49e7c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B2C:19AA62:3AF61AA:4AD292D:6B01FE7C |
| html-safe-nonce | 0c6e36fb2915b0093abe0f8b3821ae990d89ae325cb5103d17e919bb92b9c44c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjJDOjE5QUE2MjozQUY2MUFBOjRBRDI5MkQ6NkIwMUZFN0MiLCJ2aXNpdG9yX2lkIjoiODczOTE3MzY0MjQ3MzMwNDI4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d340cfb24c9bcd82e85bfba351fcddc7f9b8cdfd0cf93b2626c619a514e0baed |
| hovercard-subject-tag | issue:1801717214 |
| 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/106693/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62930cac339a533b1e29736f44980e547bf576a8a675fdd4635fe5c3eccb4cce/python/cpython/issues/106693 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62930cac339a533b1e29736f44980e547bf576a8a675fdd4635fe5c3eccb4cce/python/cpython/issues/106693 |
| og:image:alt | in bytes_characters in https://github.com/python/cpython/blob/main/Include/internal/pycore_runtime_init.h we are doing this: .bytes_characters = _Py_bytes_characters_INIT, \ where #define _Py_bytes... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pablogsal |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width