File tree 3 files changed +8
-0
lines changed
3 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -232,6 +232,8 @@ impl PublicKey {
232
232
/// Creates a public key directly from a slice
233
233
#[ inline]
234
234
pub fn from_slice ( data : & [ u8 ] ) -> Result < PublicKey , Error > {
235
+ if data. is_empty ( ) { return Err ( Error :: InvalidPublicKey ) ; }
236
+
235
237
let mut pk = ffi:: PublicKey :: new ( ) ;
236
238
unsafe {
237
239
if ffi:: secp256k1_ec_pubkey_parse (
Original file line number Diff line number Diff line change @@ -247,6 +247,8 @@ impl Signature {
247
247
#[ inline]
248
248
/// Converts a DER-encoded byte slice to a signature
249
249
pub fn from_der ( data : & [ u8 ] ) -> Result < Signature , Error > {
250
+ if data. is_empty ( ) { return Err ( Error :: InvalidSignature ) ; }
251
+
250
252
let mut ret = ffi:: Signature :: new ( ) ;
251
253
252
254
unsafe {
@@ -290,6 +292,8 @@ impl Signature {
290
292
/// 2016. It should never be used in new applications. This library does not
291
293
/// support serializing to this "format"
292
294
pub fn from_der_lax ( data : & [ u8 ] ) -> Result < Signature , Error > {
295
+ if data. is_empty ( ) { return Err ( Error :: InvalidSignature ) ; }
296
+
293
297
unsafe {
294
298
let mut ret = ffi:: Signature :: new ( ) ;
295
299
if ffi:: ecdsa_signature_parse_der_lax (
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ impl RecoverableSignature {
58
58
/// representation is nonstandard and defined by the libsecp256k1
59
59
/// library.
60
60
pub fn from_compact ( data : & [ u8 ] , recid : RecoveryId ) -> Result < RecoverableSignature , Error > {
61
+ if data. is_empty ( ) { return Err ( Error :: InvalidSignature ) ; }
62
+
61
63
let mut ret = ffi:: RecoverableSignature :: new ( ) ;
62
64
63
65
unsafe {
You can’t perform that action at this time.
0 commit comments