diff options
author | Neal H. Walfield <neal@pep.foundation> | 2017-12-11 22:34:24 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2017-12-11 22:34:24 +0100 |
commit | 600b3e806ff378f5bf2dab4cf594418056d2d0c0 (patch) | |
tree | 2619a9d53f624eeaa420a359574c62a8c88fdadb /src | |
parent | 9176ead2ca42a15598e4d5c0bc492205621aff54 (diff) |
If a compression packet is unsupported, treat it as a unknown packet
- Instead of erroring out for unknown compression algorithms, treat
compression packets with an algorithms as unknown packets.
Diffstat (limited to 'src')
-rw-r--r-- | src/openpgp/parse/parse.rs | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/openpgp/parse/parse.rs b/src/openpgp/parse/parse.rs index 16af1098..024c1f7b 100644 --- a/src/openpgp/parse/parse.rs +++ b/src/openpgp/parse/parse.rs @@ -1,6 +1,5 @@ use std; use std::fs::File; -use std::io::{Error,ErrorKind}; use num::FromPrimitive; @@ -403,7 +402,7 @@ fn literal_parser_test () { // Parse the body of a compressed data packet. fn compressed_data_parser<'a, R: BufferedReader + 'a>(mut bio: R) -> Result<PacketParser<'a>, std::io::Error> { - let algo = bio.data_consume_hard(1)?[0]; + let algo = bio.data_hard(1)?[0]; // 0 - Uncompressed // 1 - ZIP [RFC1951] @@ -420,16 +419,36 @@ fn compressed_data_parser<'a, R: BufferedReader + 'a>(mut bio: R) // filter. We can emulate this using a Limitor. Box::new(BufferedReaderLimitor::new(bio, std::u64::MAX)) }, - 1 => // Zip. - Box::new(BufferedReaderDeflate::new(bio)), - 2 => // Zlib - Box::new(BufferedReaderZlib::new(bio)), - 3 => // BZip2 - Box::new(BufferedReaderBzip::new(bio)), - _ => - // Unknown algo. XXX: Return a better error code. - return Err(Error::new(ErrorKind::UnexpectedEof, - "Unsupported compression algo")), + 1 => { + // Zip. + bio.consume(1); + Box::new(BufferedReaderDeflate::new(bio)) + }, + 2 => { + // Zlib + bio.consume(1); + Box::new(BufferedReaderZlib::new(bio)) + }, + 3 => { + // BZip2 + bio.consume(1); + Box::new(BufferedReaderBzip::new(bio)) + }, + _ => { + // Unknown algo. Return an unknown packet. + return Ok(PacketParser { + packet: Packet::Unknown(Unknown { + common: PacketCommon { + tag: Tag::CompressedData, + children: None, + content: None, + } + }), + reader: Box::new(bio), + recursion_depth: 0, + max_recursion_depth: MAX_RECURSION_DEPTH, + }); + } }; return Ok(PacketParser { |