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-144872: fix heap buffer overflow `_PyTokenizer_ensure_utf8` by AdamKorcz · Pull Request #144807 · python/cpython

Conversation

@AdamKorcz

@AdamKorcz AdamKorcz commented Feb 13, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Fixes https://issues.oss-fuzz.com/issues/451112368 and #144872

cc @ammaraskar

  • Issue: Heap buffer overflow in _PyTokenizer_ensure_utf8 #144872

Sorry, something went wrong.

Uh oh!

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

All reactions
Adam Adam
oss-fuzz-451112368: fix found crash
d30f29a
Signed-off-by: Adam <[email protected]>
@AdamKorcz
AdamKorcz requested review from lysnikolaou and pablogsal as code owners February 13, 2026 21:37
@bedevere-app bedevere-app Bot added the awaiting review label Feb 13, 2026
@bedevere-app

bedevere-app Bot commented Feb 13, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ammaraskar

ammaraskar commented Feb 13, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution! Would you mind adding a regression test for this in https://github.com/python/cpython/blob/main/Lib/test/test_tokenize.py

All reactions

Sorry, something went wrong.

Uh oh!

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

@gpshead gpshead self-assigned this Feb 14, 2026
@gpshead @claude
Add a regression test for oss-fuzz-451112368
e9b3683
Add a test covering truncated multi-byte UTF-8 sequences at end of input.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@bedevere-app

bedevere-app Bot commented Feb 14, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gpshead

gpshead commented Feb 14, 2026

Copy link
Copy Markdown
Member

I added a test.

(discussed with PSRT) We're not considering this a security issue, compile() is not safe against untrusted input (nor are the other paths that are actually executing code rather than just compiling it). It can read a couple bytes past the end of the input bytes at most. at worst a crash (ASAN in particular which I believe is how oss-fuzz found it), you'd likely get a SyntaxError as intended otherwise.

AdamKorcz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@gpshead

gpshead commented Feb 14, 2026

Copy link
Copy Markdown
Member

We do like to have issues filed to track things - read up on https://devguide.python.org/getting-started/pull-request-lifecycle/#pullrequest
As I believe you're intending to fix up a bunch of fuzzer found items, consider making a tracking issue for similar themes of those "parser crashes" or similar for this one for example - we don't need one issue per item when they aren't actually security related.

while you're working on already public oss-fuzz findings, as they are public it is fine to go ahead and make public PRs.

But if you come across any that seem actually security relevant, please reach out via email to the to PSRT, or since you're producing fix PRs maybe just use https://github.com/python/cpython/security to drop those in GHSA's for us to look over (many will probably be things we just open directly to the public as a non-concern "more of a bug" like this one)

All reactions

Sorry, something went wrong.

Uh oh!

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

@AdamKorcz AdamKorcz changed the title oss-fuzz-451112368: fix found crash gh-144872: fix found crash Feb 16, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Feb 16, 2026
Heap buffer overflow in _PyTokenizer_ensure_utf8 #144872
Closed
@AdamKorcz
add NEWS entry
2aa5f1e
Signed-off-by: Adam Korczynski <[email protected]>
@python-cla-bot

python-cla-bot Bot commented Feb 16, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@AdamKorcz AdamKorcz changed the title gh-144872: fix found crash gh-144872: fix heap buffer overflow Feb 16, 2026
aisk
aisk reviewed Feb 16, 2026
View reviewed changes
Comment thread Parser/tokenizer/helpers.c Resolved

Uh oh!

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

aisk
aisk reviewed Feb 16, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2026-02-16-12-28-43.gh-issue-144872.k9_Q30.rst Resolved

Uh oh!

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

AdamKorcz and others added 2 commits February 16, 2026 15:38
@AdamKorcz @aisk
Update Misc/NEWS.d/next/Library/2026-02-16-12-28-43.gh-issue-144872.k…
8eba1c7
…9_Q30.rst

Co-authored-by: AN Long <[email protected]>
@AdamKorcz @aisk
Update Parser/tokenizer/helpers.c
9edd6f8
Co-authored-by: AN Long <[email protected]>
@AdamKorcz

AdamKorcz commented Feb 16, 2026

Copy link
Copy Markdown
Contributor Author

@aisk thank you, is it me or you who needs to sign the CLA?

All reactions

Sorry, something went wrong.

Uh oh!

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

@AdamKorcz

AdamKorcz commented Feb 16, 2026

Copy link
Copy Markdown
Contributor Author

@aisk thank you, is it me or you who needs to sign the CLA?

it was me.

All reactions

Sorry, something went wrong.

Uh oh!

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

@StanFromIreland StanFromIreland changed the title gh-144872: fix heap buffer overflow gh-144872: fix heap buffer overflow _PyTokenizer_ensure_utf8 Feb 18, 2026
StanFromIreland
StanFromIreland reviewed Feb 18, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-02-16-12-28-43.gh-issue-144872.k9_Q30.rst Resolved

Uh oh!

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

@pablogsal
pythongh-144872: move NEWS entry to Core_and_Builtins
56d99c2
pablogsal
pablogsal approved these changes Feb 26, 2026
View reviewed changes

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I moved the news entry to Core. THanks a lot for the great work @AdamKorcz 🚀

Sorry, something went wrong.

Uh oh!

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

AdamKorcz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Feb 26, 2026
@pablogsal
pablogsal enabled auto-merge (squash) February 26, 2026 22:12
@pablogsal pablogsal added the needs backport to 3.13 only security fixes label Feb 26, 2026
@pablogsal pablogsal added the needs backport to 3.14 bugs and security fixes label Feb 26, 2026
@pablogsal
pablogsal merged commit 3fc945d into python:main Feb 26, 2026
55 checks passed

Uh oh!

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

@miss-islington-app

miss-islington-app Bot commented Feb 26, 2026

Copy link
Copy Markdown

Thanks @AdamKorcz for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 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.

@bedevere-app bedevere-app Bot removed the awaiting merge label Feb 26, 2026
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 26, 2026
@AdamKorcz @miss-islington
pythongh-144872: fix heap buffer overflow _PyTokenizer_ensure_utf8 (p…
0fa0a35
…ythonGH-144807)

(cherry picked from commit 3fc945d)

Co-authored-by: AdamKorcz <[email protected]>
@miss-islington-app

miss-islington-app Bot commented Feb 26, 2026

Copy link
Copy Markdown

Sorry, @AdamKorcz and @pablogsal, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 3fc945df22a169e039c3f21b44c0d08390a00c0c 3.13
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 pablogsal and unassigned gpshead Feb 26, 2026
@bedevere-app

bedevere-app Bot commented Feb 26, 2026

Copy link
Copy Markdown

GH-145287 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 Feb 26, 2026
pablogsal pushed a commit that referenced this pull request Feb 26, 2026
@miss-islington @AdamKorcz
[3.14] gh-144872: fix heap buffer overflow _PyTokenizer_ensure_utf8 (…
0810124
…GH-144807) (#145287)

Co-authored-by: AdamKorcz <[email protected]>
@pablogsal

pablogsal commented Feb 27, 2026

Copy link
Copy Markdown
Member

@AdamKorcz can you do the 3.13 backport following #144807 (comment) ?

All reactions

Sorry, something went wrong.

Uh oh!

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

brijkapadia pushed a commit to brijkapadia/cpython that referenced this pull request Feb 28, 2026
@AdamKorcz @brijkapadia
pythongh-144872: fix heap buffer overflow _PyTokenizer_ensure_utf8 (p…
18910cc
…ython#144807)
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Mar 2, 2026
@AdamKorcz @StanFromIreland
[3.13] pythongh-144872: fix heap buffer overflow `_PyTokenizer_ensure…
7665cee
…_utf8` (pythonGH-144807)

(cherry picked from commit 3fc945d)

Co-authored-by: AdamKorcz <[email protected]>
@bedevere-app

bedevere-app Bot commented Mar 2, 2026

Copy link
Copy Markdown

GH-145441 is a backport of this pull request to the 3.13 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.13 only security fixes label Mar 2, 2026
pablogsal pushed a commit that referenced this pull request Mar 2, 2026
@StanFromIreland @AdamKorcz
[3.13] gh-144872: fix heap buffer overflow _PyTokenizer_ensure_utf8 (…
5577bd1
…GH-144807) (#145441)

(cherry picked from commit 3fc945d)

Co-authored-by: AdamKorcz <[email protected]>
@bedevere-bot

bedevere-bot commented Mar 3, 2026

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 MacOS M1 NoGIL 3.13 (tier-2) has failed when building commit 5577bd1.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1408/builds/1843) and take a look at the build logs.
  4. Check if the failure is related to this commit (5577bd1) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1408/builds/1843

Failed tests:

  • test_httpservers
  • test.test_concurrent_futures.test_thread_pool

Failed subtests:

  • test_free_reference - test.test_concurrent_futures.test_thread_pool.ThreadPoolExecutorTest.test_free_reference
  • test_large_content_length_truncated - test.test_httpservers.CGIHTTPServerTestCase.test_large_content_length_truncated

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/test_concurrent_futures/executor.py", line 147, in test_free_reference
    for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/support/__init__.py", line 2596, in sleeping_retry
    for _ in busy_retry(timeout, err_msg, error=error):
             ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/support/__init__.py", line 2566, in busy_retry
    raise AssertionError(msg)
AssertionError: timeout (45.9 seconds)


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/test_concurrent_futures/executor.py", line 147, in test_free_reference
    for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/support/__init__.py", line 2596, in sleeping_retry
    for _ in busy_retry(timeout, err_msg, error=error):
             ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/support/__init__.py", line 2566, in busy_retry
    raise AssertionError(msg)
AssertionError: timeout (45.8 seconds)


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/test_httpservers.py", line 1028, in test_large_content_length_truncated
    res = self.request('/cgi-bin/file1.py', 'POST', b'x', headers)
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/test_httpservers.py", line 89, in request
    return self.connection.getresponse()
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/http/client.py", line 1450, in getresponse
    response.begin()
    ~~~~~~~~~~~~~~^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/http/client.py", line 336, in begin
    version, status, reason = self._read_status()
                              ~~~~~~~~~~~~~~~~~^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/http/client.py", line 297, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
               ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/socket.py", line 719, in readinto
    return self._sock.recv_into(b)
           ~~~~~~~~~~~~~~~~~~~~^^^
ConnectionResetError: [Errno 54] Connection reset by peer
All reactions

Sorry, something went wrong.

Uh oh!

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

ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@AdamKorcz @ljfp
pythongh-144872: fix heap buffer overflow _PyTokenizer_ensure_utf8 (p…
8fc386a
…ython#144807)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@aisk aisk aisk left review comments
@StanFromIreland StanFromIreland StanFromIreland left review comments
@pablogsal pablogsal pablogsal approved these changes
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner

Uh oh!

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

Assignees

@pablogsal pablogsal

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.

7 participants

@AdamKorcz @ammaraskar @gpshead @pablogsal @bedevere-bot @aisk @StanFromIreland
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.