summaryrefslogtreecommitdiffstats
path: root/openpgp/src/armor.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-12-16 09:27:10 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-12-16 09:28:47 +0100
commit8dc869f6b28ae2cd3bb9cc4ff7c4bc30a7c9c27f (patch)
tree58ab47a44d9b4c96364fed1296944ecc4dd76bdf /openpgp/src/armor.rs
parentd84d1c3fa460f814f400ffed42897601da525e69 (diff)
openpgp: Fix corner case.
- Previously, if a zero-sized read was requested, we concluded that we reached the end of the armored block. - Fixes #404.
Diffstat (limited to 'openpgp/src/armor.rs')
-rw-r--r--openpgp/src/armor.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs
index 12456ade..7d1c4102 100644
--- a/openpgp/src/armor.rs
+++ b/openpgp/src/armor.rs
@@ -1019,6 +1019,14 @@ impl<'a> Read for Reader<'a> {
self.initialize()?;
}
+ if buf.len() == 0 {
+ // Short-circuit here. Otherwise, we copy 0 bytes into
+ // the buffer, which means we decoded 0 bytes, and we
+ // wrongfully assume that we reached the end of the
+ // armored block.
+ return Ok(0);
+ }
+
if self.finalized {
assert_eq!(self.buffer.len(), 0);
return Ok(0);
@@ -1611,4 +1619,14 @@ mod test {
payload == recovered && payload == recovered_any
}
}
+
+ /// Tests issue #404, zero-sized reads break reader.
+ #[test]
+ fn zero_sized_read() {
+ let mut r = Reader::from_bytes(crate::tests::file("armor/test-1.asc"),
+ None);
+ let mut buf = Vec::new();
+ r.read(&mut buf).unwrap();
+ r.read(&mut buf).unwrap();
+ }
}