Skip to content

Commit 6d848c5

Browse files
zugzwangtwiss
authored andcommitted
Don't panic on corrupt fingerprint subpacket
1 parent 41db4ea commit 6d848c5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

openpgp/keys_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,3 +1303,16 @@ func TestKeyValidateOnDecrypt(t *testing.T) {
13031303
t.Fatal("Failed to detect invalid ElGamal key")
13041304
}
13051305
}
1306+
1307+
// Should not panic (generated with go-fuzz)
1308+
func TestCorruptKeys(t *testing.T) {
1309+
data := `-----BEGIN PGP PUBLIC KEY BLOCK00000
1310+
1311+
mQ00BF00000BCAD0000000000000000000000000000000000000000000000000
1312+
0000000000000000000000000000000000000000000000000000000000000000
1313+
0000000000000000000000000000000000000000000000000000000000000000
1314+
0000000000000000000000000000000000000000000000000000000000000000
1315+
0000000000000000000000000000000000000000000000000000000000000000
1316+
000000000000000000000000000000000000ABE000G0Dn000000000000000000iQ00BB0BAgAGBCG00000`
1317+
ReadArmoredKeyRing(strings.NewReader(data))
1318+
}

openpgp/packet/signature.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r
418418
}
419419
case issuerFingerprintSubpacket:
420420
v, l := subpacket[0], len(subpacket[1:])
421-
if v < 5 && l != 20 || v == 5 && l != 32 {
421+
if v == 5 && l != 32 || v != 5 && l != 20 {
422422
return nil, errors.StructuralError("bad fingerprint length")
423423
}
424424
sig.IssuerFingerprint = make([]byte, l)

0 commit comments

Comments
 (0)