GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-146196: Fix potential Undefined Behavior in _PyUnicodeWriter_WriteASCIIString by ashm-dev · Pull Request #146201 · python/cpython

Conversation

@ashm-dev

@ashm-dev ashm-dev commented Mar 20, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

_PyUnicodeWriter_WriteASCIIString

  • Issue: Undefined Behavior in _PyUnicodeWriter_WriteASCIIString: NULL pointer passed to memcpy when len is 0 #146196

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot mentioned this pull request Mar 20, 2026
Undefined Behavior in _PyUnicodeWriter_WriteASCIIString: NULL pointer passed to memcpy when len is 0 #146196
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Mar 20, 2026
vstinner
vstinner reviewed Mar 20, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-03-20-13-55-14.gh-issue-146196.Zg70Kb.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/unicode_writer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/unicode_writer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ashm-dev
ashm-dev requested a review from AA-Turner as a code owner March 20, 2026 15:06
@ashm-dev
ashm-dev force-pushed the ub branch from fe544e1 to bc550a2 Compare March 20, 2026 15:16
@ashm-dev
pythongh-146196: Fix potential Undefined Behavior in _PyUnicodeWriter…
694c82a
…_WriteASCIIString
@ashm-dev
ashm-dev force-pushed the ub branch from bc550a2 to 694c82a Compare March 20, 2026 15:23
vstinner
vstinner reviewed Mar 20, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-03-20-13-55-14.gh-issue-146196.Zg70Kb.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
Update Misc/NEWS.d/next/Core_and_Builtins/2026-03-20-13-55-14.gh-issu…
63bbe18
…e-146196.Zg70Kb.rst
@vstinner vstinner added the needs backport to 3.14 bugs and security fixes label Mar 20, 2026
@vstinner
vstinner enabled auto-merge (squash) March 20, 2026 15:34
@vstinner
vstinner merged commit cd10a2e into python:main Mar 20, 2026
52 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting review label Mar 20, 2026
@miss-islington-app

miss-islington-app Bot commented Mar 20, 2026

Copy link
Copy Markdown

Thanks @ashm-dev for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Mar 20, 2026

Copy link
Copy Markdown

Sorry, @ashm-dev and @vstinner, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker cd10a2e65c25682095f6ee4a9b9a181938a50d2e 3.14
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned vstinner Mar 20, 2026
vstinner added a commit to vstinner/cpython that referenced this pull request Mar 20, 2026
@ashm-dev @vstinner
pythongh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCI…
ca11535
…IString() (python#146201)

Avoid calling memcpy(data + writer->pos, NULL, 0)
which has an undefined behavior.

Co-authored-by: Victor Stinner <[email protected]>
(cherry picked from commit cd10a2e)
@bedevere-app

bedevere-app Bot commented Mar 20, 2026

Copy link
Copy Markdown

GH-146220 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Mar 20, 2026
@ashm-dev
ashm-dev deleted the ub branch March 20, 2026 16:02
vstinner added a commit that referenced this pull request Mar 20, 2026
@vstinner @ashm-dev
[3.14] gh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASC…
6e73225
…IIString() (#146201) (#146220)

gh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCIIString() (#146201)

Avoid calling memcpy(data + writer->pos, NULL, 0)
which has an undefined behavior.


(cherry picked from commit cd10a2e)

Co-authored-by: Shamil <[email protected]>
@serhiy-storchaka serhiy-storchaka mentioned this pull request Mar 20, 2026
[3.14] gh-146056: Fix repr() for lists and tuples containing NULLs (GH-146129) #146155
Merged
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Mar 22, 2026
@CuriousLearner
Merge remote-tracking branch 'upstream/main' into fix-pythongh-138577
2691ad9
* upstream/main: (1475 commits)
  Docs: replace all `datetime` imports with `import datetime as dt` (python#145640)
  pythongh-146153: Use `frozendict` in pure python fallback for `curses.has_key` (python#146154)
  pythongh-138234: clarify returncode behavior for subprocesses created with `shell=True` (python#138536)
  pythongh-140947: fix contextvars handling for server tasks in asyncio  (python#141158)
  pythonGH-100108: Add async generators best practices section (python#141885)
  pythonGH-145667: Merge `GET_ITER` and `GET_YIELD_FROM_ITER` (pythonGH-146120)
  pythongh-146228: Better fork support in cached FastPath (python#146231)
  pythongh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic_std.h (pythongh-146229)
  pythongh-145980: Fix copy/paste mistake in binascii.c (python#146230)
  pythongh-146092: Raise MemoryError on allocation failure in _zoneinfo (python#146165)
  pythongh-91279: Note `SOURCE_DATE_EPOCH` support in `ZipFile.writestr()` doc (python#139396)
  pythongh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCIIString() (python#146201)
  pythongh-143930: Reject leading dashes in webbrowser URLs
  pythongh-145916: Soft-deprecate ctypes.util.find_library (pythonGH-145919)
  pythongh-146205: Check the errno with != 0 in close impls in select module (python#146206)
  pythongh-146171: Fix nested AttributeError suggestions (python#146188)
  pythongh-146099: Optimize _GUARD_CODE_VERSION+IP via function version symbols (pythonGH-146101)
  pythongh-145980: Add support for alternative alphabets in the binascii module (pythonGH-145981)
  pythongh-145754: Update signature retrieval in unittest.mock to use forwardref annotation format (python#145756)
  pythongh-145177: Add emscripten run --test, uses test args from config.toml (python#146160)
  ...
@pablogsal pablogsal mentioned this pull request Apr 4, 2026
gh-130273: Fix traceback color output with unicode characters #142529
Merged
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@ashm-dev @vstinner @ljfp
pythongh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCI…
be90080
…IString() (python#146201)

Avoid calling memcpy(data + writer->pos, NULL, 0)
which has an undefined behavior.

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@AA-Turner AA-Turner Awaiting requested review from AA-Turner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@vstinner vstinner

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ashm-dev @vstinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.