diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-05-29 13:12:52 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-05-29 13:29:36 +0200 |
commit | 9ecc55512f4f08130181ab82956a6f19e6bf76a8 (patch) | |
tree | 5f9351e47badba8bd519c3b117a7556c42a01f98 /openpgp | |
parent | b99ce58dfc4d68556319c52a7067997b917aa192 (diff) |
openpgp: Fix crash due to invalid handling of UTF-8 input.
- Fixes #515.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/armor.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index b3692154..09eb92e7 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -798,7 +798,7 @@ impl<'a> Reader<'a> { let line = if line.ends_with(&"\r\n"[..]) { // \r\n. &line[..line.len() - 2] - } else if line.len() > 0 { + } else if line.ends_with("\n") { // \n. &line[..line.len() - 1] } else { @@ -1637,4 +1637,21 @@ mod test { r.read(&mut buf).unwrap(); r.read(&mut buf).unwrap(); } + + /// Crash in armor parser due to indexing not aligned with UTF-8 + /// characters. + #[test] + fn issue_515() { + let data = [63, 9, 45, 10, 45, 10, 45, 45, 45, 45, 45, 66, 69, + 71, 73, 78, 32, 80, 71, 80, 32, 77, 69, 83, 83, + 65, 71, 69, 45, 45, 45, 45, 45, 45, 152, 152, 152, + 152, 152, 152, 255, 29, 152, 152, 152, 152, 152, + 152, 152, 152, 152, 152, 10, 91, 45, 10, 45, 14, + 0, 36, 0, 0, 30, 122, 4, 2, 204, 152]; + + let mut reader = Reader::from_bytes(&data[..], None); + let mut buf = Vec::new(); + // `data` is malformed, expect an error. + reader.read_to_end(&mut buf).unwrap_err(); + } } |