| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
📝 Walkthrough
WalkthroughThis PR fixes a panic in the hash wrapping logic when __hash__ returns an oversized integer. It replaces the unsafe modulo-based fallback with proper sentinel-based normalization using utilities from the common hash module, and adds test coverage for oversized hash values and unhashable built-in types. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
📜 Recent review details Configuration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro 📥 CommitsReviewing files that changed from the base of the PR and between ee74713 and a14d5c1. 📒 Files selected for processing (2)
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
crates/common/src/hash.rs (2)extra_tests/snippets/builtin_hash.py (1) crates/vm/src/types/slot.rs (1)🔇 Additional comments (3) crates/vm/src/types/slot.rs (2)extra_tests/snippets/builtin_hash.py (1) 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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
|
Code has been automatically formatted The code in this PR has been formatted using cargo fmt --all. git pull origin copilot/fix-hash-wrapper-panic |
Sorry, something went wrong.
|
@copilot Investigate the proper behavior of CPython and ensure test_dataclasses work |
Sorry, something went wrong.
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Adjusted the hash wrapper to leave in-range integers unchanged and only normalize on overflow, matching CPython’s conversion; test_dataclasses now passes (commit 7fb03b2). |
Sorry, something went wrong.
|
@youknowone: I'll review the changes in this PR. I'll pay special attention to:
I'll analyze the implementation to ensure that:
Review triggered.
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Calling hash() on an object whose __hash__ returns a very large integer could panic in the hash wrapper when the value didn’t fit into i64.
Example:
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 to unwrap() on None instead of raising a Python exception or normalizing safely.
Proof of Concept:
thread 'main' panicked at crates/vm/src/types/slot.rs:369:72: called `Option::unwrap()` on a `None` value stack backtrace: 0: __rustc::rust_begin_unwind at /rustc/11ad40bb839ca16f74784b4ab72596ad85587298/library/std/src/panicking.rs:697:5 1: core::panicking::panic_fmt at /rustc/11ad40bb839ca16f74784b4ab72596ad85587298/library/core/src/panicking.rs:75:14 2: core::panicking::panic at /rustc/11ad40bb839ca16f74784b4ab72596ad85587298/library/core/src/panicking.rs:145:5 3: core::option::unwrap_failed at /rustc/11ad40bb839ca16f74784b4ab72596ad85587298/library/core/src/option.rs:2072:5 4: core::option::Option<T>::unwrap at /home/jackfromeast/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1005:21 5: rustpython_vm::types::slot::hash_wrapper::{{closure}} at ./crates/vm/src/types/slot.rs:369:72 6: core::option::Option<T>::unwrap_or_else at /home/jackfromeast/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1050:21 7: rustpython_vm::types::slot::hash_wrapper at ./crates/vm/src/types/slot.rs:369:10 8: rustpython_vm::protocol::object::<impl rustpython_vm::object::core::PyObject>::hash at ./crates/vm/src/protocol/object.rs:663:20 9: rustpython_vm::stdlib::builtins::builtins::hash at ./crates/vm/src/stdlib/builtins.rs:440:13 10: core::ops::function::Fn::call at /home/jackfromeast/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:79:5 11: rustpython_vm::function::builtin::<impl rustpython_vm::function::builtin::sealed::PyNativeFnInternal<(rustpython_vm::function::builtin::OwnedParam<T1>,),R,rustpython_vm::vm::VirtualMachine> for F>::call_ at ./crates/vm/src/function/builtin.rs:126:17 12: <F as rustpython_vm::function::builtin::IntoPyNativeFn<(T,R,VM)>>::call at ./crates/vm/src/function/builtin.rs:92:14 13: rustpython_vm::function::builtin::into_func::{{closure}} at ./crates/vm/src/function/builtin.rs:50:40 14: <rustpython_vm::builtins::builtin_func::PyNativeFunction as rustpython_vm::types::slot::Callable>::call at ./crates/vm/src/builtins/builtin_func.rs:73:9 15: rustpython_vm::types::slot::Callable::slot_call at ./crates/vm/src/types/slot.rs:1028:9 16: rustpython_vm::protocol::callable::PyCallable::invoke at ./crates/vm/src/protocol/callable.rs:52:22 17: rustpython_vm::protocol::callable::<impl rustpython_vm::object::core::PyObject>::call_with_args at ./crates/vm/src/protocol/callable.rs:33:18 18: rustpython_vm::protocol::callable::<impl rustpython_vm::object::core::PyObject>::call at ./crates/vm/src/protocol/callable.rs:22:14 19: rustpython_vm::frame::ExecutingFrame::execute_call at ./crates/vm/src/frame.rs:1880:30 20: rustpython_vm::frame::ExecutingFrame::execute_instruction at ./crates/vm/src/frame.rs:667:22 21: rustpython_vm::frame::ExecutingFrame::run at ./crates/vm/src/frame.rs:372:31 22: rustpython_vm::frame::<impl rustpython_vm::object::core::Py<rustpython_vm::frame::Frame>>::run::{{closure}} at ./crates/vm/src/frame.r... </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes RustPython/RustPython#6550 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added comprehensive test cases for hash function behavior, validating edge cases and handling of built-in types. * **Refactor** * Optimized internal hash computation logic. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->