Skip to content

gh-153200: Fix math.isqrt() for int subclasses with overridden comparison operators#153203

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:fix/math/isqrt-index
Jul 6, 2026
Merged

gh-153200: Fix math.isqrt() for int subclasses with overridden comparison operators#153203
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:fix/math/isqrt-index

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

The final check-and-correct comparison in the arbitrary precision path could call a comparison operator overridden in an int subclass, producing an off-by-one result for arguments not less than 2**64. Compare by value with int's tp_richcompare instead (same approach as PyDict_Type.tp_richcompare in Objects/odictobject.c).

🤖 Generated with Claude Code

…comparison operators

The final check-and-correct comparison in the arbitrary precision path
could call a comparison operator overridden in an int subclass.
Compare by value with int's tp_richcompare.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 6, 2026
@serhiy-storchaka serhiy-storchaka merged commit 3a1b547 into python:main Jul 6, 2026
62 checks passed
@miss-islington-app

Copy link
Copy Markdown

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

@serhiy-storchaka serhiy-storchaka deleted the fix/math/isqrt-index branch July 6, 2026 18:10
@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 3a1b5473f217fc493f743c9ca8b877d2e76f8e6b 3.14

@bedevere-app

bedevere-app Bot commented Jul 6, 2026

Copy link
Copy Markdown

GH-153223 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 6, 2026
@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 3a1b5473f217fc493f743c9ca8b877d2e76f8e6b 3.13

@bedevere-app

bedevere-app Bot commented Jul 6, 2026

Copy link
Copy Markdown

GH-153225 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 Jul 6, 2026
serhiy-storchaka added a commit that referenced this pull request Jul 6, 2026
… comparison operators (GH-153203) (GH-153225)

The final check-and-correct comparison in the arbitrary precision path
could call a comparison operator overridden in an int subclass.
Compare by value with int's tp_richcompare.

(cherry picked from commit 3a1b547)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 6, 2026
… comparison operators (GH-153203) (GH-153225) (GH-153226)

The final check-and-correct comparison in the arbitrary precision path
could call a comparison operator overridden in an int subclass.
Compare by value with int's tp_richcompare.

(cherry picked from commit 3a1b547)
(cherry picked from commit a9a91d0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 6, 2026
… comparison operators (GH-153203) (GH-153223)

The final check-and-correct comparison in the arbitrary precision path
could call a comparison operator overridden in an int subclass.
Compare by value with int's tp_richcompare.
(cherry picked from commit 3a1b547)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.13 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant