Skip to content

Commit

Permalink
v1.17: sdk: add bounds check when instantiating Keypair from byte a…
Browse files Browse the repository at this point in the history
…rray (backport of #34817) (#34822)

sdk: add bounds check when instantiating `Keypair` from byte array (#34817)

(cherry picked from commit 6dbcdc0)

Co-authored-by: Trent Nelson <trent@solana.com>
  • Loading branch information
mergify[bot] and t-nelson authored Jan 18, 2024
1 parent fbb11a8 commit 3eae1c4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk/src/signer/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ impl Keypair {

/// Recovers a `Keypair` from a byte array
pub fn from_bytes(bytes: &[u8]) -> Result<Self, ed25519_dalek::SignatureError> {
if bytes.len() < ed25519_dalek::KEYPAIR_LENGTH {
return Err(ed25519_dalek::SignatureError::from_source(String::from(
"candidate keypair byte array is too short",
)));
}
let secret =
ed25519_dalek::SecretKey::from_bytes(&bytes[..ed25519_dalek::SECRET_KEY_LENGTH])?;
let public =
Expand Down

0 comments on commit 3eae1c4

Please sign in to comment.