-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Handle oversized __hash__ results without panicking #6561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThis PR fixes a panic in the hash wrapping logic when Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (2)**/*.rs📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.py📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧬 Code graph analysis (2)crates/vm/src/types/slot.rs (1)
extra_tests/snippets/builtin_hash.py (1)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
|
Code has been automatically formatted The code in this PR has been formatted using git pull origin copilot/fix-hash-wrapper-panic |
|
@copilot Investigate the proper behavior of CPython and ensure test_dataclasses work |
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
|
@coderabbitai review |
|
@youknowone: I'll review the changes in this PR. I'll pay special attention to:
I'll analyze the implementation to ensure that:
✅ Actions performedReview triggered.
|
Calling
hash()on an object whose__hash__returns a very large integer could panic in the hash wrapper when the value didn’t fit intoi64.hash_biginthelper so arbitrarily large__hash__results are safely reduced to a validPyHashinstead of panicking.1 << 63from__hash__hashes to the expected value.Example:
Original prompt
This section details on the original issue you should resolve
<issue_title>Panic in hash wrapping when user hash returns oversized int</issue_title>
<issue_description>### What happened?
Calling
hash()on an object whose__hash__returns an oversized integer (e.g.,1 << 63) causes a panic in hash_wrapper. The wrapper attempts to convert the BigInt to i64, then falls back to% u64::MAX, but that remainder can still be outside i64 and leads tounwrap()on None instead of raising a Python exception or normalizing safely.Proof of Concept:
Affected Versions
Python 3.13.0alpha (heads/main-dirty:21300f689, Dec 13 2025, 22:16:49) [RustPython 0.4.0 with rustc 1.90.0-nightly (11ad40bb8 2025-06-28)]Vulnerable Code
Rust Output