Skip to content

Commit

Permalink
Merge the fix for an infinite loop in reading PNG files.
Browse files Browse the repository at this point in the history
  • Loading branch information
kamadak committed Jan 5, 2021
2 parents f57a972 + 7c643da commit 1b05eab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "exif"
version = "0.5.2"
version = "0.5.3"
authors = ["KAMADA Ken'ichi <kamada@nanohz.org>"]
edition = "2018"

Expand Down
13 changes: 13 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ impl<T> 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),
Expand Down Expand Up @@ -98,6 +101,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 data = [];
Expand Down

0 comments on commit 1b05eab

Please sign in to comment.