diff --git a/pg/src/main/java/org/bouncycastle/bcpg/OnePassSignaturePacket.java b/pg/src/main/java/org/bouncycastle/bcpg/OnePassSignaturePacket.java index 42c7e6e201..e3fa3d6a1d 100644 --- a/pg/src/main/java/org/bouncycastle/bcpg/OnePassSignaturePacket.java +++ b/pg/src/main/java/org/bouncycastle/bcpg/OnePassSignaturePacket.java @@ -1,5 +1,7 @@ package org.bouncycastle.bcpg; +import org.bouncycastle.util.io.Streams; + import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -32,9 +34,12 @@ public class OnePassSignaturePacket hashAlgorithm = in.read(); keyAlgorithm = in.read(); - if (version == VERSION_3) { + if (version == VERSION_3) + { keyID = StreamUtil.readKeyID(in); - } else if (version == VERSION_6) { + } + else if (version == VERSION_6) + { int saltLen = in.read(); if (saltLen < 0) { throw new IOException("Version 6 OPS packet has invalid salt length."); @@ -45,6 +50,11 @@ public class OnePassSignaturePacket fingerprint = new byte[32]; in.readFully(fingerprint); } + else + { + Streams.drain(in); + throw new UnsupportedPacketVersionException("Unsupported OnePassSignature packet version encountered: " + version); + } isContaining = in.read(); }