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-71810: Fix _PyLong_AsByteArray() undefined behavior by vstinner · Pull Request #138873 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Sep 13, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

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

  • Issue: int.to_bytes() and int.from_bytes(): raise ValueError when bytes count is zero #71810

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
pythongh-71810: Fix _PyLong_AsByteArray() undefined behavior
3906765
Don't read p[-1] when p is an empty string: when n==0.
@vstinner vstinner added the skip news label Sep 13, 2025
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 13, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Sep 13, 2025
int.to_bytes() and int.from_bytes(): raise ValueError when bytes count is zero #71810
Closed
@vstinner vstinner mentioned this pull request Sep 13, 2025
gh-71810: fix corner case (length==0) for int.to_bytes() #138739
Merged
@vstinner

vstinner commented Sep 13, 2025

Copy link
Copy Markdown
Member Author

cc @skirpichev @serhiy-storchaka

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner mentioned this pull request Sep 13, 2025
gh-129813, PEP 782: Use PyBytesWriter in _PyBytes_FormatEx() #138839
Merged
serhiy-storchaka
serhiy-storchaka approved these changes Sep 13, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka 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. 👍

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Sep 13, 2025
@skirpichev
Merge branch 'main' into int_to_bytes_undef
4b89325
@skirpichev skirpichev added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Sep 14, 2025
skirpichev
skirpichev approved these changes Sep 14, 2025
View reviewed changes
@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

miss-islington-app Bot commented Sep 14, 2025

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 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 merge label Sep 14, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 14, 2025
@vstinner @miss-islington
pythongh-71810: Fix _PyLong_AsByteArray() undefined behavior (pythonG…
e234ea6
…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 <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 14, 2025
@vstinner @miss-islington
pythongh-71810: Fix _PyLong_AsByteArray() undefined behavior (pythonG…
fd1444e
…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 <[email protected]>
@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.

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

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 Sep 14, 2025
vstinner added a commit that referenced this pull request Sep 14, 2025
@miss-islington @vstinner
[3.13] gh-71810: Fix _PyLong_AsByteArray() undefined behavior (GH-138873
a902058
) (#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 <[email protected]>
@bedevere-bot

bedevere-bot commented Sep 14, 2025

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)>
All reactions

Sorry, something went wrong.

Uh oh!

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

vstinner added a commit that referenced this pull request Oct 7, 2025
@miss-islington @vstinner
[3.14] gh-71810: Fix _PyLong_AsByteArray() undefined behavior (GH-138873
b343009
) (#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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@skirpichev skirpichev skirpichev approved these changes
@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes

Uh oh!

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

Assignees

No one assigned

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.

4 participants

@vstinner @bedevere-bot @skirpichev @serhiy-storchaka
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.