summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-06-05 12:09:27 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-06-05 12:52:09 +0200
commit4c7f664493ba35181eca0a6ff8630a4ddf2e01b2 (patch)
tree2ae2db3be2af94de6fd4ce69d44133cfe92aa612
parent2e0cb0de66e73ff6681276e90f31690a991bffc5 (diff)
openpgp: Fix parsing.
- Previously, a signature packet with a malformed embedded signature would break the parsing, because the embedded signature is turned into an unknown packet, hence `Signature::from_reader` returns `Error::InvalidOperation` and so does `SubpacketArea::parse`. Errors from that function are handled using php_try!, but that did not make the packet turn into an unknown packet, but terminated the parsing. - Looking at `Subpacket::parse` revealed that there are more errors that would terminate parsing in the outlined way, notably `Error::MalformedPacket`, but there may be others. - Fix this by tweaking php_try! to return unknown packets on any `openpgp::Error`.
-rw-r--r--openpgp/src/parse.rs20
-rw-r--r--openpgp/tests/data/edge-cases/malformed-embedded-sig.pgpbin0 -> 642 bytes
2 files changed, 14 insertions, 6 deletions
diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs
index e84cca47..6121ef31 100644
--- a/openpgp/src/parse.rs
+++ b/openpgp/src/parse.rs
@@ -394,12 +394,7 @@ macro_rules! make_php_try {
Err(e) => e,
};
let e = match e.downcast::<Error>() {
- Ok(e) => match e {
- Error::MalformedMPI(_) =>
- return $parser.error(e.into()),
- _ =>
- e.into(),
- },
+ Ok(e) => return $parser.error(e.into()),
Err(e) => e,
};
@@ -5519,4 +5514,17 @@ mod test {
panic!("expected unknown packet, got: {:?}", packet);
}
}
+
+ /// Malformed subpackets must not cause a hard parsing error.
+ #[test]
+ fn malformed_embedded_signature() -> Result<()> {
+ let ppr = PacketParser::from_bytes(
+ crate::tests::file("edge-cases/malformed-embedded-sig.pgp"))?;
+ let packet = &ppr.unwrap().packet;
+ if let Packet::Unknown(_) = packet {
+ Ok(())
+ } else {
+ panic!("expected unknown packet, got: {:?}", packet);
+ }
+ }
}
diff --git a/openpgp/tests/data/edge-cases/malformed-embedded-sig.pgp b/openpgp/tests/data/edge-cases/malformed-embedded-sig.pgp
new file mode 100644
index 00000000..5b2f1597
--- /dev/null
+++ b/openpgp/tests/data/edge-cases/malformed-embedded-sig.pgp
Binary files differ