Title: Copying bytes object to shared memory list truncates trailing zeros · Issue #106939 · python/cpython · GitHub
Open Graph Title: Copying bytes object to shared memory list truncates trailing zeros · Issue #106939 · python/cpython
X Title: Copying bytes object to shared memory list truncates trailing zeros · Issue #106939 · python/cpython
Description: Bug report tl;dr; See stack overflow post When copying a bytes object to a shareable list, the trailing zeros are stripped causing data loss. This doesn't appear in the documentation as far as I can tell, and seems to be unexpected behav...
Open Graph Description: Bug report tl;dr; See stack overflow post When copying a bytes object to a shareable list, the trailing zeros are stripped causing data loss. This doesn't appear in the documentation as far as I ca...
X Description: Bug report tl;dr; See stack overflow post When copying a bytes object to a shareable list, the trailing zeros are stripped causing data loss. This doesn't appear in the documentation as far as ...
Opengraph URL: https://github.com/python/cpython/issues/106939
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Copying bytes object to shared memory list truncates trailing zeros","articleBody":"# Bug report\r\n\r\n**tl;dr; See [stack overflow post](https://stackoverflow.com/questions/76734284/copying-bytes-object-to-shared-memory-list-truncates-trailing-zeros)**\r\n\r\nWhen copying a `bytes` object to a shareable list, the trailing zeros are stripped causing data loss. This doesn't appear in the documentation as far as I can tell, and seems to be unexpected behavior related to the implementation.\r\n\r\nExample code:\r\n```python\r\nfrom multiprocessing import shared_memory as shm\r\n\r\nshmList = shm.ShareableList([bytes(50)])\r\ntestBytes = bytes.fromhex(\"00112233445566778899aabbccddeeff0000\")\r\n\r\nshmList[0] = testBytes\r\nprint(testBytes)\r\nprint(shmList[0])\r\n\r\nshmList.shm.close()\r\nshmList.shm.unlink()\r\n```\r\n\r\nOutput:\r\n```\r\nb'\\x00\\x11\"3DUfw\\x88\\x99\\xaa\\xbb\\xcc\\xdd\\xee\\xff\\x00\\x00'\r\nb'\\x00\\x11\"3DUfw\\x88\\x99\\xaa\\xbb\\xcc\\xdd\\xee\\xff'\r\n```\r\n\r\nOffending portion of CPython [code](https://github.com/python/cpython/blob/d81b4f8ff84311fa737e62f2883442ec06d7d5d8/Lib/multiprocessing/shared_memory.py#L280):\r\n```python\r\n_back_transforms_mapping = {\r\n 0: lambda value: value, # int, float, bool\r\n 1: lambda value: value.rstrip(b'\\x00').decode(_encoding), # str\r\n 2: lambda value: value.rstrip(b'\\x00'), # bytes\r\n 3: lambda _value: None, # None\r\n }\r\n```\r\n\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-107266\r\n* gh-107269\r\n* gh-107270\r\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/pinkhamr-fb","@type":"Person","name":"pinkhamr-fb"},"datePublished":"2023-07-21T00:12:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/106939/cpython/issues/106939"}
| 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:36ea4b01-62b3-055c-8107-5eb739e0ba5e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1DE:CD10D:D48CA8:1130953:696B02BB |
| html-safe-nonce | a6acaf37c306feb4542c79a6f132f1b77a26b05ad7982471871a3d2edef9f0a2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMURFOkNEMTBEOkQ0OENBODoxMTMwOTUzOjY5NkIwMkJCIiwidmlzaXRvcl9pZCI6IjY0MDMwMjk0NDY3MDgzNjM5NjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9c520a9d39e4065361812dd92c46ff905639ce63958308dec49b51e851aadc88 |
| hovercard-subject-tag | issue:1814969520 |
| 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/106939/issue_layout |
| twitter:image | https://opengraph.githubassets.com/19d5759fb1b3da1f10ebbded119634f5c5e1e4adfb154c0888492ca467a76055/python/cpython/issues/106939 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/19d5759fb1b3da1f10ebbded119634f5c5e1e4adfb154c0888492ca467a76055/python/cpython/issues/106939 |
| og:image:alt | Bug report tl;dr; See stack overflow post When copying a bytes object to a shareable list, the trailing zeros are stripped causing data loss. This doesn't appear in the documentation as far as I ca... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pinkhamr-fb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width