Skip to content
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

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

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

t-nelson
Copy link
Contributor

Problem

no bounds check on candidate by array in Keypair::from_bytes()

h/t: certik

Summary of Changes

add one

@t-nelson t-nelson added the v1.17 PRs that should be backported to v1.17 label Jan 17, 2024
Copy link
Contributor

mergify bot commented Jan 17, 2024

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. One question, which probably doesn't need to hold up merging this.

@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it doesn't matter for slice indexing, but is there any reason this should be catching longer byte slices as well? (ie !=)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i considered it, but decided to punt under the impression that someone is likely abusing the poorly defined api. clearly this method signature should be

fn from_bytes(bytes: &[u8; 64]) -> Result<Self, NotTheDamnDependencysError>

but here we are

Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (0e8f2de) 81.7% compared to head (0a765a7) 81.7%.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #34817     +/-   ##
=========================================
- Coverage    81.7%    81.7%   -0.1%     
=========================================
  Files         825      825             
  Lines      223249   223250      +1     
=========================================
- Hits       182609   182598     -11     
- Misses      40640    40652     +12     

@t-nelson t-nelson merged commit 6dbcdc0 into solana-labs:master Jan 18, 2024
45 checks passed
@t-nelson t-nelson deleted the kpbbc branch January 18, 2024 01:51
mergify bot pushed a commit that referenced this pull request Jan 18, 2024
t-nelson added a commit that referenced this pull request Jan 18, 2024
mergify bot added a commit that referenced this pull request Jan 18, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.17 PRs that should be backported to v1.17
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants