Explicit checks for empty slices

This commit is contained in:
Elichai Turkel 2019-08-08 16:01:08 -04:00
parent b7e20c5b12
commit ddb8e4fdf2
No known key found for this signature in database
GPG Key ID: 9383CDE9E8E66A7F
3 changed files with 8 additions and 0 deletions

View File

@ -232,6 +232,8 @@ impl PublicKey {
/// Creates a public key directly from a slice
#[inline]
pub fn from_slice(data: &[u8]) -> Result<PublicKey, Error> {
if data.is_empty() {return Err(Error::InvalidPublicKey);}
let mut pk = ffi::PublicKey::new();
unsafe {
if ffi::secp256k1_ec_pubkey_parse(

View File

@ -247,6 +247,8 @@ impl Signature {
#[inline]
/// Converts a DER-encoded byte slice to a signature
pub fn from_der(data: &[u8]) -> Result<Signature, Error> {
if data.is_empty() {return Err(Error::InvalidSignature);}
let mut ret = ffi::Signature::new();
unsafe {
@ -290,6 +292,8 @@ impl Signature {
/// 2016. It should never be used in new applications. This library does not
/// support serializing to this "format"
pub fn from_der_lax(data: &[u8]) -> Result<Signature, Error> {
if data.is_empty() {return Err(Error::InvalidSignature);}
unsafe {
let mut ret = ffi::Signature::new();
if ffi::ecdsa_signature_parse_der_lax(

View File

@ -58,6 +58,8 @@ impl RecoverableSignature {
/// representation is nonstandard and defined by the libsecp256k1
/// library.
pub fn from_compact(data: &[u8], recid: RecoveryId) -> Result<RecoverableSignature, Error> {
if data.is_empty() {return Err(Error::InvalidSignature);}
let mut ret = ffi::RecoverableSignature::new();
unsafe {