diff --git a/src/XrdFileCache/XrdFileCacheIOEntireFile.cc b/src/XrdFileCache/XrdFileCacheIOEntireFile.cc index 68144bcfb0d..09ff327a14f 100644 --- a/src/XrdFileCache/XrdFileCacheIOEntireFile.cc +++ b/src/XrdFileCache/XrdFileCacheIOEntireFile.cc @@ -64,7 +64,6 @@ void IOEntireFile::StartPrefetch() { pthread_t tid; XrdSysThread::Run(&tid, PrefetchRunner, (void *)(m_prefetch), 0, "XrdFileCache Prefetcher"); - } @@ -87,8 +86,13 @@ int IOEntireFile::Read (char *buff, long long off, int size) clLog()->Debug(XrdCl::AppMsg, "IO::Read() [%p] %lld@%d %s", this, off, size, m_io.Path()); // protect from reads over the file size + if (off >= m_io.FSize() || off < 0) + { + errno = EINVAL; + return -1; + } if (off + size > m_io.FSize()) - size = m_io.FSize() - off; + size = m_io.FSize() - off; ssize_t bytes_read = 0; ssize_t retval = 0; @@ -97,7 +101,6 @@ int IOEntireFile::Read (char *buff, long long off, int size) clLog()->Debug(XrdCl::AppMsg, "IO::Read() read from prefetch retval = %d %s", retval, m_io.Path()); if (retval > 0) { - bytes_read += retval; buff += retval; size -= retval; diff --git a/src/XrdFileCache/XrdFileCacheIOFileBlock.cc b/src/XrdFileCache/XrdFileCacheIOFileBlock.cc index d01846838ad..ed3e54c4b24 100644 --- a/src/XrdFileCache/XrdFileCacheIOFileBlock.cc +++ b/src/XrdFileCache/XrdFileCacheIOFileBlock.cc @@ -126,16 +126,21 @@ bool IOFileBlock::ioActive() //______________________________________________________________________________ int IOFileBlock::Read (char *buff, long long off, int size) { + // protect from reads over the file size + if (off >= m_io.FSize() || off < 0) + { + errno = EINVAL; + return -1; + } + if (off + size > m_io.FSize()) + size = m_io.FSize() - off; + long long off0 = off; int idx_first = off0/m_blocksize; int idx_last = (off0+size-1)/m_blocksize; int bytes_read = 0; clLog()->Debug(XrdCl::AppMsg, "IOFileBlock::Read() %lld@%d block range [%d-%d] \n %s", off, size, idx_first, idx_last, m_io.Path()); - // protect from reads over the file size - if (off + size > m_io.FSize()) - size = m_io.FSize() - off; - for (int blockIdx = idx_first; blockIdx <= idx_last; ++blockIdx ) { // locate block