summaryrefslogtreecommitdiffstats
path: root/openpgp/src/parse.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2022-12-05 17:53:43 +0100
committerJustus Winter <justus@sequoia-pgp.org>2023-05-11 15:01:43 +0200
commitf6307652fb2cbf4e0fbd3f897b1ec70863fcfa61 (patch)
tree865e2fb93da841edc648c14c74dc5b12da1e7410 /openpgp/src/parse.rs
parente369609d6b1225400bc116656195c77fc684438e (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/src/parse.rs')
-rw-r--r--openpgp/src/parse.rs28
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-----
+");
+ }
}