diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-01-19 12:22:53 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-05-12 10:29:41 +0200 |
commit | cce50ad4f3645011b5f8b473f6e83850105200eb (patch) | |
tree | 22c11fb9415bf075e0df3d67050f8d0f5b25bd69 /openpgp | |
parent | b9badbdd2e9bd996fa6afd8187ffe8653bdaf294 (diff) |
openpgp: Fix a crash related to stray signatures.
- See #977.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/parse/stream.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index a6a02b67..730f515b 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -694,7 +694,16 @@ impl IMessageStructure { _ => (), } } - panic!("signature unaccounted for"); + + // As a last resort, push a new signature group for this + // signature. This may not accurately describe the structure, + // but if we get to this point, we failed to grasp the message + // structure in some way, so there is nothing we can do really. + t!("signature unaccounted for"); + self.layers.push(IMessageLayer::SignatureGroup { + sigs: vec![sig], + count: 0, + }); } fn push_bare_signature(&mut self, sig: Signature) { @@ -3894,4 +3903,25 @@ EK8= Ok(()) } + + /// Checks for a crash with signatures that are unaccounted for. + #[test] + fn unaccounted_signatures() -> Result<()> { + let p = P::new(); + let m = b"-----BEGIN PGP MESSAGE----- + +wgoEAAAAAAB6CkAAxADLBq8AAKurq8IKBCC/CAAAAAD0sA== +=KRn6 +-----END PGP MESSAGE----- +"; + + let mut h = VHelper::new(0, 0, 0, 0, vec![ + Cert::from_bytes(crate::tests::key("testy.pgp"))?, + ]); + h.error_out = false; + VerifierBuilder::from_bytes(m)? + .with_policy(&p, None, h) + .unwrap(); + Ok(()) + } } |