Merge the fix for an infinite loop in reading PNG files.
This commit is contained in:
commit
1b05eab57e
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "exif"
|
name = "exif"
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
authors = ["KAMADA Ken'ichi <kamada@nanohz.org>"]
|
authors = ["KAMADA Ken'ichi <kamada@nanohz.org>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
13
src/util.rs
13
src/util.rs
|
@ -56,6 +56,9 @@ impl<T> BufReadExt for T where T: io::BufRead {
|
||||||
fn discard_exact(&mut self, mut len: usize) -> io::Result<()> {
|
fn discard_exact(&mut self, mut len: usize) -> io::Result<()> {
|
||||||
while len > 0 {
|
while len > 0 {
|
||||||
let consume_len = match self.fill_buf() {
|
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),
|
Ok(buf) => buf.len().min(len),
|
||||||
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
|
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
|
@ -98,6 +101,16 @@ mod tests {
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use super::*;
|
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]
|
#[test]
|
||||||
fn read8_len() {
|
fn read8_len() {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
Loading…
Reference in New Issue