From: Kostya Shishkov Date: Fri, 12 Nov 2021 10:37:24 +0000 (+0100) Subject: core/byteio: fix corner case when reading partial buffer at the end of file X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=f88724a81e18ae9521863faf94ae9d2c2cb60e15;p=nihav.git core/byteio: fix corner case when reading partial buffer at the end of file --- diff --git a/nihav-core/src/io/byteio.rs b/nihav-core/src/io/byteio.rs index 3fbee94..b3d0621 100644 --- a/nihav-core/src/io/byteio.rs +++ b/nihav-core/src/io/byteio.rs @@ -600,8 +600,11 @@ impl ByteIO for FileReader { 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); }