Merge pull request #1010 from sr-gi/enforce_signature_length
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Tue, 20 Jul 2021 23:25:40 +0000 (23:25 +0000)
committerGitHub <noreply@github.com>
Tue, 20 Jul 2021 23:25:40 +0000 (23:25 +0000)
lightning/src/util/message_signing.rs

index 2055b4087749ada5b3baef731770608baceb629e..8beff835a4bffe1f0b3d59e672380323b6164f98 100644 (file)
@@ -36,6 +36,11 @@ fn sigrec_encode(sig_rec: RecoverableSignature) -> Vec<u8> {
 }
 
 fn sigrec_decode(sig_rec: Vec<u8>) -> Result<RecoverableSignature, Error> {
+    // Signature must be 64 + 1 bytes long (compact signature + recovery id)
+    if sig_rec.len() != 65 {
+        return Err(Error::InvalidSignature);
+    }
+
     let rsig = &sig_rec[1..];
     let rid = sig_rec[0] as i32 - 31;