From f21df24616ea611c5d5d0e0e2f8042eb74d5ff48 Mon Sep 17 00:00:00 2001 From: KAMADA Ken'ichi Date: Mon, 4 Jan 2021 11:06:15 +0900 Subject: [PATCH 1/2] Fix an infinite loop in reading PNG files. --- src/util.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util.rs b/src/util.rs index e5dd0e4..a4cd6dc 100644 --- a/src/util.rs +++ b/src/util.rs @@ -56,6 +56,9 @@ impl BufReadExt for T where T: io::BufRead { fn discard_exact(&mut self, mut len: usize) -> io::Result<()> { while len > 0 { let consume_len = match self.fill_buf() { + Ok(buf) if buf.is_empty() => + return Err(io::Error::new( + io::ErrorKind::UnexpectedEof, "unexpected EOF")), Ok(buf) => buf.len().min(len), Err(e) if e.kind() == io::ErrorKind::Interrupted => continue, Err(e) => return Err(e), @@ -99,6 +102,16 @@ mod tests { use std::io::Read; use super::*; + #[test] + fn discard_exact() { + let mut buf = b"abc".as_ref(); + buf.discard_exact(1).unwrap(); + assert_eq!(buf, b"bc"); + buf.discard_exact(2).unwrap(); + assert_eq!(buf, b""); + buf.discard_exact(1).unwrap_err(); + } + #[test] fn read8_len() { let mut reader = Cursor::new([]); From 7c643da1972b30dc70b31b4c10c5ed0444e36d53 Mon Sep 17 00:00:00 2001 From: KAMADA Ken'ichi Date: Tue, 5 Jan 2021 17:49:15 +0900 Subject: [PATCH 2/2] Increment the version to 0.5.3. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e761db1..e0f8e89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "exif" -version = "0.5.2" +version = "0.5.3" authors = ["KAMADA Ken'ichi "] edition = "2018"