Skip to content

Commit

Permalink
Make sure requested offset is reasonable.
Browse files Browse the repository at this point in the history
  • Loading branch information
osschar committed Dec 17, 2015
1 parent 532d39a commit d2ea7d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/XrdFileCache/XrdFileCacheIOEntireFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ void IOEntireFile::StartPrefetch()
{
pthread_t tid;
XrdSysThread::Run(&tid, PrefetchRunner, (void *)(m_prefetch), 0, "XrdFileCache Prefetcher");

}


Expand All @@ -87,8 +86,10 @@ 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)
return 0;
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;
Expand All @@ -97,7 +98,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;
Expand Down
10 changes: 6 additions & 4 deletions src/XrdFileCache/XrdFileCacheIOFileBlock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,18 @@ 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)
return 0;
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
Expand Down

0 comments on commit d2ea7d0

Please sign in to comment.