summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-07-15 17:58:56 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-07-15 18:05:05 +0200
commitf598646623655dac80ee5bfafeeb50b406002a85 (patch)
tree3af029edeab7d55233d572b29528662f3249e986
parent7abb783db72eb2f46a8f31a798f6456df26b916c (diff)
openpgp: Gracefully handle malformed notation names.
-rw-r--r--openpgp/src/parse.rs19
-rw-r--r--openpgp/tests/data/edge-cases/malformed-notation-name.pgpbin0 -> 394 bytes
2 files changed, 18 insertions, 1 deletions
diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs
index 75e59da9..1944c5bd 100644
--- a/openpgp/src/parse.rs
+++ b/openpgp/src/parse.rs
@@ -1491,7 +1491,11 @@ impl Subpacket {
SubpacketValue::NotationData(
NotationData::new(
std::str::from_utf8(
- &php.parse_bytes("notation name", name_len)?)?,
+ &php.parse_bytes("notation name", name_len)?)
+ .map_err(|e| anyhow::Error::from(
+ Error::MalformedPacket(
+ format!("Malformed notation name: {}", e)))
+ )?,
&php.parse_bytes("notation value", value_len)?,
Some(flags.into())))
},
@@ -5538,4 +5542,17 @@ mod test {
panic!("expected unknown packet, got: {:?}", packet);
}
}
+
+ /// Malformed notation names must not cause hard parsing errors.
+ #[test]
+ fn malformed_notation_name() -> Result<()> {
+ let ppr = PacketParser::from_bytes(
+ crate::tests::file("edge-cases/malformed-notation-name.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-notation-name.pgp b/openpgp/tests/data/edge-cases/malformed-notation-name.pgp
new file mode 100644
index 00000000..43c9701b
--- /dev/null
+++ b/openpgp/tests/data/edge-cases/malformed-notation-name.pgp
Binary files differ