Merge the fix for an infinite loop in reading PNG files.

This commit is contained in:
KAMADA Ken'ichi 2021-01-05 17:55:31 +09:00
commit 1b05eab57e
2 changed files with 14 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "exif"
version = "0.5.2"
version = "0.5.3"
authors = ["KAMADA Ken'ichi <kamada@nanohz.org>"]
edition = "2018"

View File

@ -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),
@ -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 = [];