diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-12-05 17:53:43 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-05-11 15:01:43 +0200 |
commit | f6307652fb2cbf4e0fbd3f897b1ec70863fcfa61 (patch) | |
tree | 865e2fb93da841edc648c14c74dc5b12da1e7410 /openpgp | |
parent | e369609d6b1225400bc116656195c77fc684438e (diff) |
buffered-reader: Fix returning partial reads ending in errors.
- Make sure that we return the data we already have in our buffer,
even though we encountered an IO error while filling it.
- Notably, the packet parser assumes that data once read can be
requested through the buffered reader protocol again and again.
Unfortunately, that was not the case, leading to a panic.
- As the generic reader is used to implement the buffered reader
protocol on top of io::Read, this problem affects among other
things the compression container. Demonstrate this using test.
- Fixes #1005.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/parse.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index d8b4fd07..d414cbe4 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -6463,4 +6463,32 @@ mod test { Ok(()) } + + /// Tests for a panic in the packet parser. + fn parse_message(message: &str) { + eprintln!("parsing {:?}", message); + let mut ppr = match PacketParser::from_bytes(message) { + Ok(ppr) => ppr, + Err(_) => return, + }; + while let PacketParserResult::Some(pp) = ppr { + dbg!(&pp.packet); + if let Ok((_, tmp)) = pp.recurse() { + ppr = tmp; + } else { + break; + } + } + } + + /// Tests issue 1005. + #[test] + fn panic_on_short_zip() { + parse_message("-----BEGIN PGP SIGNATURE----- + +owGjAA0= +zXvj +-----END PGP SIGNATURE----- +"); + } } |