Skip to content

Commit 8e2f128

Browse files
mareteagl
authored andcommitted
openpgp: Fix panic on v3 public keys with too-short modulus.
Found using gofuzz. Fixes golang/go#11504 Change-Id: I49cf01e75e37c5d87dad58c5349161d79d0b72f5 Reviewed-on: https://go-review.googlesource.com/12635 Reviewed-by: Adam Langley <[email protected]>
1 parent 7938751 commit 8e2f128

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

openpgp/packet/public_key_v3.go

+5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ func (pk *PublicKeyV3) parseRSA(r io.Reader) (err error) {
9595
return
9696
}
9797

98+
// RFC 4880 Section 12.2 requires the low 8 bytes of the
99+
// modulus to form the key id.
100+
if len(pk.n.bytes) < 8 {
101+
return errors.StructuralError("v3 public key modulus is too short")
102+
}
98103
if len(pk.e.bytes) > 3 {
99104
err = errors.UnsupportedError("large public exponent")
100105
return

openpgp/read_test.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,10 @@ func TestNoArmoredData(t *testing.T) {
369369
}
370370
}
371371

372-
func TestIssue11503(t *testing.T) {
373-
data := "8c040402000aa430aa8228b9248b01fc899a91197130303030"
374-
375-
buf, err := hex.DecodeString(data)
372+
func testReadMessageError(t *testing.T, messageHex string) {
373+
buf, err := hex.DecodeString(messageHex)
376374
if err != nil {
377-
t.Errorf("hex.DecodeSting(): %v", err)
375+
t.Errorf("hex.DecodeString(): %v", err)
378376
}
379377

380378
kr, err := ReadKeyRing(new(bytes.Buffer))
@@ -392,6 +390,14 @@ func TestIssue11503(t *testing.T) {
392390
}
393391
}
394392

393+
func TestIssue11503(t *testing.T) {
394+
testReadMessageError(t, "8c040402000aa430aa8228b9248b01fc899a91197130303030")
395+
}
396+
397+
func TestIssue11504(t *testing.T) {
398+
testReadMessageError(t, "9303000130303030303030303030983002303030303030030000000130")
399+
}
400+
395401
const testKey1KeyId = 0xA34D7E18C20C31BB
396402
const testKey3KeyId = 0x338934250CCC0360
397403

0 commit comments

Comments
 (0)