diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-04-28 12:57:54 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2022-04-28 13:22:47 +0200 |
commit | 583f781a0fb66b503c492540510eb747c6f47247 (patch) | |
tree | 88a7b8d3267bb4dd6d623fbbd516ce3951e89c0e /openpgp/src/parse.rs | |
parent | 31a9ae094eeb41e720119f92a8afeb1a6123a01e (diff) |
openpgp: Rework handing of unknown compression algorithms.
- Currently, if we don't understand a compression algorithm, parsing
a compressed data packet fails and it is turned into an Unknown
packet. This is rather unfortunate, and deviates from what we do
for the encryption containers.
- Encryption containers are either not decrypted, in which case they
have a Body::Unprocessed, decrypted with Body::Processed, or
decrypted and parsed Body::Structured.
- Likewise, if we don't understand a compression algorithm, we
should simply return a compressed data packet with an unprocessed
body. This change does exactly that.
- Fixes #830.
Diffstat (limited to 'openpgp/src/parse.rs')
-rw-r--r-- | openpgp/src/parse.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index 45bdd7b1..386c27b5 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -2555,6 +2555,9 @@ impl CompressedData { let algo: CompressionAlgorithm = php_try!(php.parse_u8("algo")).into(); + let recursion_depth = php.recursion_depth(); + let mut pp = php.ok(Packet::CompressedData(CompressedData::new(algo)))?; + #[allow(unreachable_patterns)] match algo { CompressionAlgorithm::Uncompressed => (), @@ -2563,16 +2566,15 @@ impl CompressedData { | CompressionAlgorithm::Zlib => (), #[cfg(feature = "compression-bzip2")] CompressionAlgorithm::BZip2 => (), - CompressionAlgorithm::Unknown(_) - | CompressionAlgorithm::Private(_) => - return php.fail("unknown compression algorithm"), - _ => - return php.fail("unsupported compression algorithm"), + _ => { + // We don't know or support this algorithm. Return a + // CompressedData packet without pushing a filter, so + // that it has an opaque body. + t!("Algorithm {} unknown or unsupported.", algo); + return Ok(pp.set_encrypted(true)); + }, } - let recursion_depth = php.recursion_depth(); - let mut pp = php.ok(Packet::CompressedData(CompressedData::new(algo)))?; - t!("Pushing a decompressor for {}, recursion depth = {:?}.", algo, recursion_depth); @@ -4699,8 +4701,6 @@ impl <'a> PacketParser<'a> { } } }, - // self.encrypted should always be false. - Packet::CompressedData(_) => unreachable!(), // Packets that don't recurse. Packet::Unknown(_) | Packet::Signature(_) | Packet::OnePassSig(_) | Packet::PublicKey(_) | Packet::PublicSubkey(_) @@ -4708,7 +4708,8 @@ impl <'a> PacketParser<'a> { | Packet::Marker(_) | Packet::Trust(_) | Packet::UserID(_) | Packet::UserAttribute(_) | Packet::Literal(_) | Packet::PKESK(_) | Packet::SKESK(_) - | Packet::SEIP(_) | Packet::MDC(_) | Packet::AED(_) => { + | Packet::SEIP(_) | Packet::MDC(_) | Packet::AED(_) + | Packet::CompressedData(_) => { // Drop through. t!("A {:?} packet is not a container, not recursing.", self.packet.tag()); @@ -4805,7 +4806,7 @@ impl <'a> PacketParser<'a> { Packet::Literal(p) => set_or_extend(rest, p.container_mut(), false), Packet::Unknown(p) => set_or_extend(rest, p.container_mut(), false), Packet::CompressedData(p) => - set_or_extend(rest, p.deref_mut(), true), + set_or_extend(rest, p.deref_mut(), ! self.encrypted), Packet::SEIP(p) => set_or_extend(rest, p.deref_mut(), ! self.encrypted), Packet::AED(p) => |