summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-10-30 16:11:32 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-10-30 16:36:42 +0100
commitf893274486c61e0a4709e8d36e88c72efdc1446e (patch)
tree3faca21c62c497f35fb8fca2a29384b710579fe1 /openpgp
parent9fbf8c5e9d083ad18e8d1ffe39577192590b3386 (diff)
openpgp: Avoid substracting with overflow.
- Fixes #348.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/packet/signature/mod.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs
index 094e2d0f..4bd659bc 100644
--- a/openpgp/src/packet/signature/mod.rs
+++ b/openpgp/src/packet/signature/mod.rs
@@ -606,12 +606,16 @@ impl Signature4 {
// We need to zero-pad them at the front, because
// the MPI encoding drops leading zero bytes.
let half = ed25519::ED25519_SIGNATURE_SIZE / 2;
- for _ in 0..half - r.value().len() {
- signature.push(0);
+ if r.value().len() < half {
+ for _ in 0..half - r.value().len() {
+ signature.push(0);
+ }
}
signature.extend_from_slice(r.value());
- for _ in 0..half - s.value().len() {
- signature.push(0);
+ if s.value().len() < half {
+ for _ in 0..half - s.value().len() {
+ signature.push(0);
+ }
}
signature.extend_from_slice(s.value());