Skip to content

Commit ddb8e4f

Browse files
committed
Explicit checks for empty slices
1 parent b7e20c5 commit ddb8e4f

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/key.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ impl PublicKey {
232232
/// Creates a public key directly from a slice
233233
#[inline]
234234
pub fn from_slice(data: &[u8]) -> Result<PublicKey, Error> {
235+
if data.is_empty() {return Err(Error::InvalidPublicKey);}
236+
235237
let mut pk = ffi::PublicKey::new();
236238
unsafe {
237239
if ffi::secp256k1_ec_pubkey_parse(

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ impl Signature {
247247
#[inline]
248248
/// Converts a DER-encoded byte slice to a signature
249249
pub fn from_der(data: &[u8]) -> Result<Signature, Error> {
250+
if data.is_empty() {return Err(Error::InvalidSignature);}
251+
250252
let mut ret = ffi::Signature::new();
251253

252254
unsafe {
@@ -290,6 +292,8 @@ impl Signature {
290292
/// 2016. It should never be used in new applications. This library does not
291293
/// support serializing to this "format"
292294
pub fn from_der_lax(data: &[u8]) -> Result<Signature, Error> {
295+
if data.is_empty() {return Err(Error::InvalidSignature);}
296+
293297
unsafe {
294298
let mut ret = ffi::Signature::new();
295299
if ffi::ecdsa_signature_parse_der_lax(

src/recovery/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ impl RecoverableSignature {
5858
/// representation is nonstandard and defined by the libsecp256k1
5959
/// library.
6060
pub fn from_compact(data: &[u8], recid: RecoveryId) -> Result<RecoverableSignature, Error> {
61+
if data.is_empty() {return Err(Error::InvalidSignature);}
62+
6163
let mut ret = ffi::RecoverableSignature::new();
6264

6365
unsafe {

0 commit comments

Comments
 (0)