diff --git a/src/crc32.rs b/src/crc32.rs index 0bc60f5d..ed0101e6 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -42,7 +42,7 @@ impl Read for Crc32Reader { let count = match self.inner.read(buf) { - Ok(0) if !self.check_matches() => { return Err(io::Error::new(io::ErrorKind::Other, "Invalid checksum")) }, + Ok(0) if !buf.is_empty() && !self.check_matches() => { return Err(io::Error::new(io::ErrorKind::Other, "Invalid checksum")) }, Ok(n) => n, Err(e) => return Err(e), }; @@ -52,7 +52,7 @@ impl Read for Crc32Reader } #[cfg(test)] -mod tests +mod test { use super::*; use std::io::Read; @@ -86,4 +86,15 @@ mod tests // Can keep reading 0 bytes after the end assert_eq!(reader.read(&mut buf).unwrap(), 0); } + + #[test] + fn test_zero_read() + { + let data: &[u8] = b"1234"; + let mut buf = [0; 5]; + + let mut reader = Crc32Reader::new(data, 0x9be3e0a3); + assert_eq!(reader.read(&mut buf[..0]).unwrap(), 0); + assert_eq!(reader.read(&mut buf).unwrap(), 4); + } }