GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||
GeezerVison is showing github.com — gh-71810: fix corner case (length==0) for int.to_bytes() by skirpichev · Pull Request #138739 · python/cpython Conversation
|
|
@serhiy-storchaka: I would suggest to backport this change to Python 3.13 and 3.14. What do you think? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It seems there are no enough tests for signed=True. Please add also tests for (128).to_bytes(0, 'big', signed=True) and (-129).to_bytes(0, 'big', signed=True).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Disclaimer: I was thinking about |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Or better add several tests for extreme values and values just above the limit for all combination of signedness and n=0, 1, 2. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Done. There are such tests, but rather for "automatic" value for length parameter (determined by result): Line 1262 in 1ce0553
It seems to be a big refactoring of tests. Maybe it does make sense as a separate pr? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would add much more tests. Anyway, LGTM. 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Serhiy Storchaka <[email protected]>
|
Thanks @skirpichev for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…nGH-138739) ```pycon >>> (0).to_bytes(0, 'big', signed=True) b'' >>> (-1).to_bytes(0, 'big', signed=True) # was b'' Traceback (most recent call last): File "<python-input-0>", line 1, in <module> (-1).to_bytes(0, 'big', signed=True) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ OverflowError: int too big to convert ``` (cherry picked from commit 011179a) Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
…nGH-138739) ```pycon >>> (0).to_bytes(0, 'big', signed=True) b'' >>> (-1).to_bytes(0, 'big', signed=True) # was b'' Traceback (most recent call last): File "<python-input-0>", line 1, in <module> (-1).to_bytes(0, 'big', signed=True) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ OverflowError: int too big to convert ``` (cherry picked from commit 011179a) Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-138782 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-138783 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Merged, thank you. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…38739) (#138783) gh-71810: Fix corner case (length==0) for int.to_bytes() (GH-138739) ```pycon >>> (0).to_bytes(0, 'big', signed=True) b'' >>> (-1).to_bytes(0, 'big', signed=True) # was b'' Traceback (most recent call last): File "<python-input-0>", line 1, in <module> (-1).to_bytes(0, 'big', signed=True) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ OverflowError: int too big to convert ``` (cherry picked from commit 011179a) Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
…38739) (#138782) Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
| p += pincr; | ||
| } | ||
| else if (j == n && n > 0 && is_signed) { | ||
| else if (j == n && is_signed) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This change introduced an undefined behavior: unsigned char msb = *(p - pincr); read is out of the bounds if n == 0. I wrote #138873 to fix it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry. Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.