-
Notifications
You must be signed in to change notification settings - Fork 41
Fix TryFromIntError when deserializing P2P gossip messages with out-of-range nonce values #1830
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
base: develop
Are you sure you want to change the base?
Conversation
OCaml Reference Validation ResultsRepository: https://github.com/MinaProtocol/mina.git Click to see full validation output |
✓ Code Reference Verification PassedAll code references in the documentation have been verified successfully! Total references checked: 1 The documentation is in sync with the codebase on the |
…prot The issue occurred when binprot streams contained i64 values outside the i32 range. The binprot library reads all integers as i64 internally and uses try_from to convert to target types, which fails with TryFromIntError for out-of-range values. The fix changes Number<u32> and Number<u64> to read i64 directly and cast to the target type, avoiding the intermediate conversion that could fail. Writing still uses the original format to maintain wire compatibility. Added regression tests to verify the fix handles: - i64 values larger than i32::MAX - Negative i64 values - All existing test cases continue to pass Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
Clarify that the asymmetry between reading (accepting any i64) and writing (casting to signed type) is intentional for robustness and wire format compatibility with the OCaml implementation. Co-authored-by: dannywillems <6018454+dannywillems@users.noreply.github.com>
61d0324 to
37d64c5
Compare
|
@copilot rebase |
Successfully rebased onto The rebased branch needs to be force-pushed to update the PR. The local branch is now based on develop@dd30271, but I'm unable to force-push directly. You may need to manually force-push or merge the changes. |
Fix TryFromIntError when handling P2P gossip messages ✅
Issue Analysis
TryFromIntErrorwhen handlingP2pNetworkPubsubIncomingMessagetry_fromto convert to target typesRoot Cause
The issue occurs in the
Number<T>binprot reading implementation:binprot_number!(u32, i32)macro reads an i32 from binprot then casts to u32try_fromto convert to i32try_fromfails withTryFromIntErrorSolution Implemented ✅
Number<u32>andNumber<u64>that read i64 directlyDesign Decisions
The fix introduces intentional asymmetry between read and write:
Testing ✅
Security Analysis ✅
Files Changed
crates/p2p-messages/src/number.rs: Custom binprot implementations for Number and Number with comprehensive testsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.