René's URL Explorer Experiment


Title: `bytearray.take_bytes()` can corrupt shared single-byte bytes objects · Issue #156995 · python/cpython · GitHub

Open Graph Title: `bytearray.take_bytes()` can corrupt shared single-byte bytes objects · Issue #156995 · python/cpython

X Title: `bytearray.take_bytes()` can corrupt shared single-byte bytes objects · Issue #156995 · python/cpython

Description: Bug report Bug description: To reproduce, run: ba = bytearray(b"abc") ba.take_bytes(2) ba[0] = 0x42 print(b'c') However, this does not print b'c' as you'd expect, instead you get: $ python3.15 /tmp/repro.py b'B' This is becasue take_byte...

Open Graph Description: Bug report Bug description: To reproduce, run: ba = bytearray(b"abc") ba.take_bytes(2) ba[0] = 0x42 print(b'c') However, this does not print b'c' as you'd expect, instead you get: $ python3.15 /tmp...

X Description: Bug report Bug description: To reproduce, run: ba = bytearray(b"abc") ba.take_bytes(2) ba[0] = 0x42 print(b'c') However, this does not print b'c' as you'd expect, inst...

Opengraph URL: https://github.com/python/cpython/issues/156995

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`bytearray.take_bytes()` can corrupt shared single-byte bytes objects","articleBody":"# Bug report\n\n### Bug description:\n\nTo reproduce, run:\n\n```python\nba = bytearray(b\"abc\")\nba.take_bytes(2)\nba[0] = 0x42\n\nprint(b'c')\n```\n\nHowever, this does not print `b'c'` as you'd expect, instead you get:\n\n```\n$ python3.15 /tmp/repro.py\nb'B'\n```\n\nThis is becasue `take_bytes()` builds the leftover buffer with `PyBytes_FromStringAndSize`, which for one remaining character returns the immortal, process-wide one-character bytes singleton instead of a fresh allocation:\n\nhttps://github.com/python/cpython/blob/14a93f4d91edf767e7b35413127cfcd6a2806983/Objects/bytearrayobject.c#L1622-L1624\n\nThe `bytearray` then installs that singleton as its mutable `ob_bytes_object`, so any write to it modifies the shared singleton that every `b'c'` refers to.\n\n### CPython versions tested on:\n\n3.15, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156996\n* gh-157260\n* gh-157292\n* gh-157373\n* gh-157436\n* gh-157477\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/StanFromIreland","@type":"Person","name":"StanFromIreland"},"datePublished":"2026-09-05T16:30:33Z","url":"https://github.com/python/cpython/issues/156995"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:87110869-91e2-fd35-d6dd-288268077506
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA00E:3A8E64:1298807:18A88FA:6B01EE01
html-safe-nonce66d5a9f5e77fb0f7d9c2f0b765a02e4a12fdd7150696fcb0d4a65b69a65567b4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDBFOjNBOEU2NDoxMjk4ODA3OjE4QTg4RkE6NkIwMUVFMDEiLCJ2aXNpdG9yX2lkIjoiNTUwOTcxNTcwNzAzMTU4MDE2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac70de38d99e790f37f7ce0643b31bb0cc49404d3f17c32b6ff90f76e8b334d50a
hovercard-subject-tagissue:5359311601
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/156995/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d327f38b9ec5cc7ab74eb36fa3de1e584eaa751c01dff37a5ed3b222eafdf059/python/cpython/issues/156995
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d327f38b9ec5cc7ab74eb36fa3de1e584eaa751c01dff37a5ed3b222eafdf059/python/cpython/issues/156995
og:image:altBug report Bug description: To reproduce, run: ba = bytearray(b"abc") ba.take_bytes(2) ba[0] = 0x42 print(b'c') However, this does not print b'c' as you'd expect, instead you get: $ python3.15 /tmp...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameStanFromIreland
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/156995#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F156995
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F156995
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/156995
Reloadhttps://github.com/python/cpython/issues/156995
Reloadhttps://github.com/python/cpython/issues/156995
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/156995
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/156995
bytearray.take_bytes() can corrupt shared single-byte bytes objectshttps://github.com/python/cpython/issues/156995#top
https://github.com/StanFromIreland
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/StanFromIreland
StanFromIrelandhttps://github.com/StanFromIreland
on Sep 5, 2026https://github.com/python/cpython/issues/156995#issue-5359311601
cpython/Objects/bytearrayobject.chttps://github.com/python/cpython/blob/14a93f4d91edf767e7b35413127cfcd6a2806983/Objects/bytearrayobject.c#L1622-L1624
14a93f4https://github.com/python/cpython/commit/14a93f4d91edf767e7b35413127cfcd6a2806983
gh-156995: Fix bytearray.take_bytes() corrupting shared single-byte bytes objects #156996https://github.com/python/cpython/pull/156996
[3.15] gh-156995: Fix bytearray.take_bytes() corrupting shared single-byte singletons (GH-156996) #157260https://github.com/python/cpython/pull/157260
gh-156995: Add caution around API behavior change #157292https://github.com/python/cpython/pull/157292
[3.14] gh-156995: Fix _PyBytes_Resize() in Free Threading (#156996) #157373https://github.com/python/cpython/pull/157373
[3.13] gh-156995: Fix _PyBytes_Resize() in Free Threading (#156996) (#157373) #157436https://github.com/python/cpython/pull/157436
[3.14] gh-156995: Fix typo in the _PyBytes_Resize() NEWS entry #157477https://github.com/python/cpython/pull/157477
Nexthttps://github.com/python/cpython/issues/156995?timeline_page=1
StanFromIrelandhttps://github.com/StanFromIreland
on Sep 5, 2026https://github.com/python/cpython/issues/156995#event-30613062187
StanFromIrelandhttps://github.com/StanFromIreland
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Sep 5, 2026https://github.com/python/cpython/issues/156995#event-30613062557
picnixzhttps://github.com/picnixz
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
on Sep 5, 2026https://github.com/python/cpython/issues/156995#event-30613406099
encukouhttps://github.com/encukou
release-blockerhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22release-blocker%22
on Sep 9, 2026https://github.com/python/cpython/issues/156995#event-30827401382
github-project-automationhttps://github.com/apps/github-project-automation
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
on Sep 9, 2026https://github.com/python/cpython/issues/156995#event-30827405978
github-project-automationhttps://github.com/apps/github-project-automation
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
on Sep 9, 2026https://github.com/python/cpython/issues/156995
https://github.com/encukou
encukouhttps://github.com/encukou
on Sep 9, 2026https://github.com/python/cpython/issues/156995#issuecomment-5601739525
vstinnerhttps://github.com/vstinner
on Sep 10, 2026https://github.com/python/cpython/issues/156995#event-30890264041
gh-156995: Fix `bytearray.take_bytes()` corrupting shared single-byte…https://github.com/python/cpython/commit/fd569ea94120815b01baf8bcbcf21e8e09102db6
gh-156995https://github.com/python/cpython/issues/156995
fd569eahttps://github.com/python/cpython/commit/fd569ea94120815b01baf8bcbcf21e8e09102db6
hugovkhttps://github.com/hugovk
on Sep 10, 2026https://github.com/python/cpython/issues/156995#event-30895717382
[3.15] gh-156995: Fix `bytearray.take_bytes()` corrupting shared sing…https://github.com/python/cpython/commit/5b8fd66db37c762dcc27b63b3ff109189a83ebd0
gh-156995https://github.com/python/cpython/issues/156995
5b8fd66https://github.com/python/cpython/commit/5b8fd66db37c762dcc27b63b3ff109189a83ebd0
hugovkhttps://github.com/hugovk
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Sep 10, 2026https://github.com/python/cpython/issues/156995#event-30896365105
github-project-automationhttps://github.com/apps/github-project-automation
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
on Sep 10, 2026https://github.com/python/cpython/issues/156995
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Sep 11, 2026https://github.com/python/cpython/issues/156995#issuecomment-5627544938
#157292https://github.com/python/cpython/pull/157292
cmaloneyhttps://github.com/cmaloney
on Sep 12, 2026https://github.com/python/cpython/issues/156995#event-31011375726
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Sep 12, 2026https://github.com/python/cpython/issues/156995#issuecomment-5643577977
cmaloneyhttps://github.com/cmaloney
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
on Sep 12, 2026https://github.com/python/cpython/issues/156995#event-31011416778
clin1234https://github.com/clin1234
on Sep 12, 2026https://github.com/python/cpython/issues/156995#event-31023921170
pythongh-156995: Fix `bytearray.take_bytes()` corrupting shared singl…https://github.com/clin1234/cpython/commit/60e24a6d0993c075dd713eb5b5af89bcce9ed841
pythongh-156995https://github.com/python/cpython/issues/156995
60e24a6https://github.com/clin1234/cpython/commit/60e24a6d0993c075dd713eb5b5af89bcce9ed841
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 12, 2026https://github.com/python/cpython/issues/156995#issuecomment-5647915607
gh-157371https://github.com/python/cpython/pull/157371
vstinnerhttps://github.com/vstinner
on Sep 12, 2026https://github.com/python/cpython/issues/156995#event-31030059922
pythongh-156995: Fix _PyBytes_Resize() in Free Threading (python#156996)https://github.com/vstinner/cpython/commit/722324d976872f282a8e6a349b085cce1759d14e
pythongh-156995https://github.com/python/cpython/issues/156995
python#156996https://github.com/python/cpython/pull/156996
722324dhttps://github.com/vstinner/cpython/commit/722324d976872f282a8e6a349b085cce1759d14e
[3.14] gh-156995: Fix _PyBytes_Resize() in Free Threading (#156996) (#…https://github.com/python/cpython/commit/fec27342ed35abec970cd690738871ee5302a0dd
gh-156995https://github.com/python/cpython/issues/156995
#156996https://github.com/python/cpython/pull/156996
#…https://github.com/python/cpython/pull/157373
fec2734https://github.com/python/cpython/commit/fec27342ed35abec970cd690738871ee5302a0dd
[3.14] pythongh-156995: Fix _PyBytes_Resize() in Free Threading (pyth…https://github.com/vstinner/cpython/commit/ae1701686c272545acda89ca4576ebcc824186ce
pythongh-156995https://github.com/python/cpython/issues/156995
pyth…https://github.com/python/cpython/pull/156996
ae17016https://github.com/vstinner/cpython/commit/ae1701686c272545acda89ca4576ebcc824186ce
[3.13] gh-156995: Fix _PyBytes_Resize() in Free Threading (#156996) (#…https://github.com/python/cpython/commit/a728f1cffac2925099adace65ee2fa600c542f75
gh-156995https://github.com/python/cpython/issues/156995
#156996https://github.com/python/cpython/pull/156996
#…https://github.com/python/cpython/pull/157373
a728f1chttps://github.com/python/cpython/commit/a728f1cffac2925099adace65ee2fa600c542f75
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Sep 14, 2026https://github.com/python/cpython/issues/156995#issuecomment-5657363847
cmaloneyhttps://github.com/cmaloney
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Sep 14, 2026https://github.com/python/cpython/issues/156995#event-31069506244
github-project-automationhttps://github.com/apps/github-project-automation
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
on Sep 14, 2026https://github.com/python/cpython/issues/156995
vstinnerhttps://github.com/vstinner
on Sep 14, 2026https://github.com/python/cpython/issues/156995#event-31091131268
pythongh-156995: Fix typo in the _PyBytes_Resize() NEWS entryhttps://github.com/vstinner/cpython/commit/45ec7669fe8b099abb105f66b43acc07f71eae07
pythongh-156995https://github.com/python/cpython/issues/156995
45ec766https://github.com/vstinner/cpython/commit/45ec7669fe8b099abb105f66b43acc07f71eae07
gh-156995: Fix typo in the _PyBytes_Resize() NEWS entry (#157477)https://github.com/python/cpython/commit/38b79e8bbd1456351ffeacf48b51cba69063bdca
gh-156995https://github.com/python/cpython/issues/156995
#157477https://github.com/python/cpython/pull/157477
38b79e8https://github.com/python/cpython/commit/38b79e8bbd1456351ffeacf48b51cba69063bdca
johnslavikhttps://github.com/johnslavik
on Sep 14, 2026https://github.com/python/cpython/issues/156995#event-31099054797
pythongh-156995: Fix `bytearray.take_bytes()` corrupting shared singl…https://github.com/johnslavik/cpython/commit/b9911f6a0508f6a54788699ad0a93877013f421f
pythongh-156995https://github.com/python/cpython/issues/156995
b9911f6https://github.com/johnslavik/cpython/commit/b9911f6a0508f6a54788699ad0a93877013f421f
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 15, 2026https://github.com/python/cpython/issues/156995#issuecomment-5687849396
gh-157572https://github.com/python/cpython/pull/157572
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/156995
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/156995
StanFromIrelandhttps://github.com/StanFromIreland
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.