]> git.nihav.org Git - nihav.git/commitdiff
core/byteio: fix corner case when reading partial buffer at the end of file
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 12 Nov 2021 10:37:24 +0000 (11:37 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 12 Nov 2021 10:37:24 +0000 (11:37 +0100)
nihav-core/src/io/byteio.rs

index 3fbee946a8989872a784adda451e6940582e7519..b3d06216d842c2a9790aff6dd7cb499bfd2d2ea0 100644 (file)
@@ -600,8 +600,11 @@ impl<T: Read+Seek> ByteIO for FileReader<T> {
         if ret.is_err() { return Err(ByteIOError::ReadError); }
         let sz = ret.unwrap();
         if sz < buf.len() {
-            if let Err(_err) = self.file.read(&mut buf[sz..][..1]) {
+            if let Err(_err) = self.file.read_exact(&mut buf[sz..][..1]) {
                 self.eof = true;
+                if sz == 0 {
+                    return Err(ByteIOError::EOF);
+                }
             } else {
                 return Ok(sz + 1);
             }