diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-01-19 12:22:53 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2023-05-16 13:50:55 +0200 |
commit | 789b0d0698d65b6372c563c36d70633e738d2b41 (patch) | |
tree | 5b70a4b0c66215ab4728219748d4ed759944a722 | |
parent | 17e7c8c5f5960ea05b68cbbbc27cee1d7ec0d42f (diff) |
openpgp: Fix a crash related to stray signatures.
- See #977.
-rw-r--r-- | openpgp/src/parse/stream.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index de604f1d..ed95d63b 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -651,7 +651,15 @@ 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. + self.layers.push(IMessageLayer::SignatureGroup { + sigs: vec![sig], + count: 0, + }); } fn push_bare_signature(&mut self, sig: Signature) { @@ -3413,4 +3421,25 @@ mod test { assert!(v.helper_ref().error == 0); 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(()) + } } |