Skip to content

Commit 963053f

Browse files
committed
avoid large allocations
If the chunk table is unable to provide the specified data window, do not allocate the frame buffer (or cache framebuffer) to that size Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
1 parent 928f9a4 commit 963053f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/lib/OpenEXR/ImfInputFile.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,21 @@ InputFile::Data::lockedSetFrameBuffer (const FrameBuffer& frameBuffer)
377377
_cachedOffset = dataWindow.min.x;
378378

379379
uint64_t tileRowSize =
380-
uint64_t (_tFile->tileYSize ()) *
381-
(static_cast<uint64_t> (dataWindow.max.x - dataWindow.min.x) +
382-
1U);
380+
static_cast<uint64_t> (_tFile->tileYSize ()) *
381+
static_cast<uint64_t> (
382+
static_cast<int64_t> (dataWindow.max.x) -
383+
static_cast<int64_t> (dataWindow.min.x) +
384+
1LL );
385+
386+
// before we allocate a (potentially large) chunk of ram, let's
387+
// quick ensure we can read the tiles
388+
if (!_ctxt->chunkTableValid (getPartIdx ()))
389+
{
390+
THROW (
391+
IEX_NAMESPACE::ArgExc,
392+
"Unable to use generic API to read with (partially?) corrupt chunk table in "
393+
<< _ctxt->fileName () << ", part " << getPartIdx () );
394+
}
383395

384396
for (FrameBuffer::ConstIterator k = frameBuffer.begin ();
385397
k != frameBuffer.end ();

src/lib/OpenEXRUtil/ImfCheckFile.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ readTileRgba (T& in, bool reduceMemory, bool reduceTime)
277277
int dwx = dw.min.x;
278278
int dwy = dw.min.y;
279279

280+
if (!in.isComplete ())
281+
return true;
282+
280283
Array2D<Rgba> pixels (h, w);
281284
in.setFrameBuffer (&pixels[-dwy][-dwx], 1, w);
282285
in.readTiles (0, in.numXTiles () - 1, 0, in.numYTiles () - 1);

0 commit comments

Comments
 (0)