diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-12-05 17:24:55 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-05-12 10:29:31 +0200 |
commit | b9badbdd2e9bd996fa6afd8187ffe8653bdaf294 (patch) | |
tree | 2049c68ed08f317aa115ce7dcbe73a0aa6551f5e /openpgp/src/armor.rs | |
parent | f6307652fb2cbf4e0fbd3f897b1ec70863fcfa61 (diff) |
openpgp: Fix crash in the packet parser.
- The packet parser hashes packet bodies to provide a robust
equality relation even when packet bodies are streamed. To hash
all bytes on the fly everywhere, we do that when it is consumed in
PacketParser::consume.
- This function assumes that if BufferedReader::data and friends
returned n bytes, future calls to these interfaces will succeed if
up to n bytes are requested, and no data was consumed in the
meantime.
- However, armor::Reader::data_helper did not provide that
guarantee, making PacketParser::consume panic with the message "It
is an error to consume more than data returns", which doesn't
quite correctly name the problem at hand.
- Fix this crash by fixing armor::Reader::data_helper in the same
way the previous commit fixes
buffered_reader::Generic::data_helper.
- Fixes #957.
Diffstat (limited to 'openpgp/src/armor.rs')
-rw-r--r-- | openpgp/src/armor.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index fb6ac87b..ed19c63a 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -1534,12 +1534,6 @@ impl<'a> Reader<'a> { self.cursor, self.buffer.as_ref().map(|buffer| buffer.len())); - // See if there is an error from the last invocation. - if let Some(e) = self.error.take() { - t!("Returning stashed error: {}", e); - return Err(e); - } - if let Some(ref buffer) = self.buffer { // We have a buffer. Make sure `cursor` is sane. assert!(self.cursor <= buffer.len()); @@ -1575,6 +1569,12 @@ impl<'a> Reader<'a> { break; } + // See if there is an error from the last invocation. + if let Some(e) = &self.error { + t!("We have a stashed error, don't poll again: {}", e); + break; + } + match self.do_read(&mut buffer_new [amount_buffered + amount_read..]) { Ok(read) => { |