Skip to content

gh-71810: Fix _PyLong_AsByteArray() undefined behavior - #138873

Merged
vstinner merged 2 commits into
python:mainfrom
vstinner:int_to_bytes_undef
Sep 14, 2025
Merged

vstinner merged 2 commits into
python:mainfrom
vstinner:int_to_bytes_undef

Conversation

@vstinner

@vstinner vstinner commented Sep 13, 2025 •

Copy link
Copy Markdown
Member

Don't read p[-1] when p is an empty string: when n==0.

Don't read p[-1] when p is an empty string: when n==0.
@vstinner

Copy link
Copy Markdown
Member Author

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. 👍

@skirpichev skirpichev added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Sep 14, 2025
@vstinner
vstinner merged commit 8b5ce31 into python:main Sep 14, 2025
@vstinner
vstinner deleted the int_to_bytes_undef branch September 14, 2025 09:25
@miss-islington-app

Copy link
Copy Markdown

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 14, 2025
…H-138873)

Don't read p[-1] when p is an empty string: when n==0.
(cherry picked from commit 8b5ce31)

Co-authored-by: Victor Stinner <vstinner@python.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 14, 2025
…H-138873)

Don't read p[-1] when p is an empty string: when n==0.
(cherry picked from commit 8b5ce31)

Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app

bedevere-app Bot commented Sep 14, 2025

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 14, 2025
@bedevere-app

bedevere-app Bot commented Sep 14, 2025

Copy link
Copy Markdown

GH-138884 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Sep 14, 2025
vstinner added a commit that referenced this pull request Sep 14, 2025
) (#138884)

gh-71810: Fix _PyLong_AsByteArray() undefined behavior (GH-138873)

Don't read p[-1] when p is an empty string: when n==0.
(cherry picked from commit 8b5ce31)

Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-bot

Copy link
Copy Markdown

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

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

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/1396/builds/1590) and take a look at the build logs.
  4. Check if the failure is related to this commit (a902058) 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/1396/builds/1590

Failed tests:

  • test.test_multiprocessing_forkserver.test_processes

Failed subtests:

  • test_repr_rlock - test.test_multiprocessing_forkserver.test_processes.WithProcessesTestLock.test_repr_rlock
  • test_repr_rlock - test.test_multiprocessing_spawn.test_processes.WithProcessesTestLock.test_repr_rlock

Test leaking resources:

  • test_processes: memory blocks

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.refleak.nogil/build/Lib/test/_test_multiprocessing.py", line 1492, in test_repr_rlock
    self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(lock))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '<RLock(SomeOtherThread, nonzero)>' != '<RLock(None, 0)>'
- <RLock(SomeOtherThread, nonzero)>
+ <RLock(None, 0)>
vstinner added a commit that referenced this pull request Oct 7, 2025
) (#138883)

gh-71810: Fix _PyLong_AsByteArray() undefined behavior (GH-138873)

Don't read p[-1] when p is an empty string: when n==0.
(cherry picked from commit 8b5ce31)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants