fix(consensus): prevent UB from untrusted bytes interpreted as enum discriminants in consensus headers #2887
Open
krishvishal wants to merge 3 commits intoapache:masterfrom
Open
fix(consensus): prevent UB from untrusted bytes interpreted as enum discriminants in consensus headers #2887krishvishal wants to merge 3 commits intoapache:masterfrom
krishvishal wants to merge 3 commits intoapache:masterfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2887 +/- ##
============================================
+ Coverage 68.33% 68.36% +0.02%
Complexity 739 739
============================================
Files 1053 1053
Lines 84763 84916 +153
Branches 61297 61460 +163
============================================
+ Hits 57923 58052 +129
- Misses 24468 24482 +14
- Partials 2372 2382 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
atharvalade
approved these changes
Mar 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2878
Rationale
Consensus headers previously stored
Command2andOperationenum values directly in repr(C) structs. This is unsound for consensus header structs: arbitrary bytes from the network are reinterpreted as enum discriminants without validation, which is undefined behavior in Rust.What changed?
commandandoperationfields in all consensus headers from enum types (Command2,Operation) to rawu8to prevent UB when interpreting untrusted bytes from the network as Rust enum discriminants.TryFrom<u8>impls forCommand2andOperationwith proper error variants (InvalidCommandByte,InvalidOperationByte) inConsensusError.dispatch_requestto returnResult<Receiver<R>, ConsensusError>instead of silently dropping unrecognized messages.