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 — [3.15] gh-158445: Detect invalid UCS4 characters in debug mode (#158502) by vstinner · Pull Request #159524 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Oct 16, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Issue: C API: Detect invalid UCS4 characters in debug mode #158445

Sorry, something went wrong.

Uh oh!

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

All reactions
vstinner added 2 commits October 16, 2026 13:28
@vstinner
pythongh-158445: Detect invalid UCS4 characters in debug mode (python…
7c5f4eb
…#158502)

In debug mode, PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND) and
PyUnicodeWriter_WriteUCS4() now raise a SystemError if a character is
not in range [U+0000; U+10ffff], instead of creating an invalid str
object.

In release mode, PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND)
raises a SystemError if the size is 1.

* In debug mode, unicode_char() no longer fails with an assertion
  error if the character is invalid. Instead, raise SystemError.
* Add tests on invalid UCS-4 characters.
* Add _testinternalcapi._Py_MAX_UNICODE.
* Add unicode_invalid_character() helper function.

(cherry picked from commit a14a4a6)
@vstinner
pythongh-158445: Skip invalid UCS-4 tests if Python is built with ass…
e0ba4e7
…ertions (python#158604)

If Python is built in release mode with assertions,
PyUnicode_FromKindAndData() and PyUnicodeWriter_Finish() fail with an
assertion error on invalid characters.

(cherry picked from commit 35bdbca)
@vstinner
vstinner requested a review from ZeroIntensity as a code owner October 16, 2026 11:29
@vstinner vstinner added skip news needs backport to 3.14 bugs and security fixes labels Oct 16, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Oct 16, 2026
C API: Detect invalid UCS4 characters in debug mode #158445
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 16, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Oct 16, 2026
gh-158445: Detect invalid UCS4 characters in debug mode #158502
Merged
@read-the-docs-community

read-the-docs-community Bot commented Oct 16, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35190753 | 📁 Comparing e0ba4e7 against main (c7a1716)

  🔍 Preview build  

140 files changed · + 1 added · ± 134 modified · - 5 deleted

+ Added

  • library/asyncio-policy.html

± Modified

  • index.html
  • license.html
  • py-modindex.html
  • builtins/exceptions.html
  • builtins/functions.html
  • builtins/stdtypes.html
  • c-api/bytes.html
  • c-api/capsule.html
  • c-api/complex.html
  • c-api/coro.html
  • and 124 more...

- Deleted

  • deprecations/pending-removal-in-3.21.html
  • library/tkinter.dialogs.html
  • library/tkinter.fontchooser.html
  • library/tkinter.systray.html
  • whatsnew/3.16.html
All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

The 3.14 backport will rely on #159525 (not merged yet).

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

"x86_64-apple-darwin/clang (Debug)" and "x86_64-apple-darwin/clang (Release)" failed on installing LLVM, make was interrupted after 60 minutes:

==> Installing dependencies for llvm@21: cmake, readline, sqlite, xz, pkgconf and [email protected]
==> Upgrading llvm@21 dependency: cmake (4.4.2 -> 4.4.4)
==> ./bootstrap --prefix=/usr/local/Cellar/cmake/4.4.4 --no-system-libs --parall
==> make
Error: The operation was canceled.
All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
vstinner merged commit 2c23505 into python:3.15 Oct 16, 2026
94 of 98 checks passed

Uh oh!

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

@vstinner
vstinner deleted the invalid_str15 branch October 16, 2026 14:47
@miss-islington-app

miss-islington-app Bot commented Oct 16, 2026

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

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 awaiting core review label Oct 16, 2026
@miss-islington-app

miss-islington-app Bot commented Oct 16, 2026

Copy link
Copy Markdown

Sorry, @vstinner, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 2c235059117a9b12d1650876d8413e80a734c31a 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 Oct 16, 2026
@bedevere-app

bedevere-app Bot commented Oct 16, 2026

Copy link
Copy Markdown

GH-159540 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 Oct 16, 2026
vstinner added a commit that referenced this pull request Oct 16, 2026
@vstinner
[3.14] gh-158445: Detect invalid UCS4 characters in debug mode (#158502…
09a7956
…) (#159524) (#159540)

[3.15] gh-158445: Detect invalid UCS4 characters in debug mode (#158502) (#159524)

* gh-158445: Detect invalid UCS4 characters in debug mode (#158502)

In debug mode, PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND) and
PyUnicodeWriter_WriteUCS4() now raise a SystemError if a character is
not in range [U+0000; U+10ffff], instead of creating an invalid str
object.

In release mode, PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND)
raises a SystemError if the size is 1.

* In debug mode, unicode_char() no longer fails with an assertion
  error if the character is invalid. Instead, raise SystemError.
* Add tests on invalid UCS-4 characters.
* Add unicode_invalid_character() helper function.

(cherry picked from commit a14a4a6)

* gh-158445: Skip invalid UCS-4 tests if Python is built with assertions (#158604)

If Python is built in release mode with assertions,
PyUnicode_FromKindAndData() and PyUnicodeWriter_Finish() fail with an
assertion error on invalid characters.

(cherry picked from commit 35bdbca)
(cherry picked from commit 2c23505)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity is a code owner

Uh oh!

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

Assignees

@vstinner vstinner

Labels

skip news

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.

1 participant

@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.