Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/lib/OpenEXR/ImfContextInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,27 @@ istream_nonparallel_read (
}
}

int64_t stream_sz = s->size ();
int64_t nend = nread + (int64_t)sz;
if (stream_sz > 0 && nend > stream_sz)
{
sz = stream_sz - nend;
}

try
{
s->read (static_cast<char*> (buffer), static_cast<int> (sz));
if (s->isMemoryMapped ())
{
char* data = s->readMemoryMapped (static_cast<int> (sz));
// TODO: in a future release, pass this through to
// core directly
if (data)
memcpy (buffer, data, sz);
}
else
{
s->read (static_cast<char*> (buffer), static_cast<int> (sz));
}
}
catch (...)
{
Expand Down
24 changes: 21 additions & 3 deletions src/lib/OpenEXRCore/parse_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ scratch_seq_read (struct _internal_exr_seq_scratch* scr, void* buf, uint64_t sz)
outbuf += nCopy;
nCopied += nCopy;
}
else if (notdone > SCRATCH_BUFFER_SIZE)
else if (notdone >= SCRATCH_BUFFER_SIZE)
{
uint64_t nPages = notdone / SCRATCH_BUFFER_SIZE;
int64_t nread = 0;
Expand All @@ -126,10 +126,28 @@ scratch_seq_read (struct _internal_exr_seq_scratch* scr, void* buf, uint64_t sz)
else
{
int64_t nread = 0;
rv = scr->ctxt->do_read (
uint64_t toread = SCRATCH_BUFFER_SIZE;

if (scr->ctxt->file_size > 0)
{
if ((scr->fileoff + SCRATCH_BUFFER_SIZE) > scr->ctxt->file_size)
{
toread = scr->ctxt->file_size - scr->fileoff;
}
}
else
{
/*
* hrm, stream only with no known size, just read 1 byte at a
* time to be safer
*/
toread = 1;
}

rv = scr->ctxt->do_read (
scr->ctxt,
scr->scratch,
SCRATCH_BUFFER_SIZE,
toread,
&(scr->fileoff),
&nread,
EXR_ALLOW_SHORT_READ);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/OpenEXRUtil/ImfCheckFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,8 @@ class PtrIStream : public IStream

virtual bool isMemoryMapped () const { return false; }

virtual int64_t size () { return end - base; }

virtual char* readMemoryMapped (int n)
{

Expand Down
Loading