Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maximumSampleCount limit to CompositeDeepScanLine #1230

Merged
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
7 changes: 7 additions & 0 deletions src/bin/exrcheck/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ main (int argc, char** argv)
}
else if (!strcmp (argv[i], "-m"))
{
//
// note for further memory reduction, calls to the folowing could be added here
// CompositeDeepScanLine::setMaximumSampleCount();
// Header::setMaxImageSize();
// Header::setMaxTileSize();

reduceMemory = true;

}
else if (!strcmp (argv[i], "-t"))
{
Expand Down
27 changes: 27 additions & 0 deletions src/lib/OpenEXR/ImfCompositeDeepScanLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,23 @@ LineCompositeTask::execute ()

} // namespace


namespace {
int64_t maximumSampleCount = 0;
}

void CompositeDeepScanLine::setMaximumSampleCount(int64_t c)
{
maximumSampleCount = c;
}

int64_t CompositeDeepScanLine::getMaximumSampleCount()
{
return maximumSampleCount;
}



void
CompositeDeepScanLine::readPixels (int start, int end)
{
Expand Down Expand Up @@ -508,6 +525,15 @@ CompositeDeepScanLine::readPixels (int start, int end)
overall_sample_count += total_sizes[ptr];
}

if (maximumSampleCount > 0 && overall_sample_count > maximumSampleCount)
{
throw IEX_NAMESPACE::ArgExc (
"Cannot composite scanline: total sample count on scanline exceeds "
"limit set by CompositeDeepScanLine::setMaximumSampleCount()"
);
}


//
// allocate arrays for pixel data
// samples array accessed as in pixels[channel][sample]
Expand Down Expand Up @@ -599,4 +625,5 @@ CompositeDeepScanLine::frameBuffer () const
return _Data->_outputFrameBuffer;
}


OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
17 changes: 17 additions & 0 deletions src/lib/OpenEXR/ImfCompositeDeepScanLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ class IMF_EXPORT_TYPE CompositeDeepScanLine

struct IMF_HIDDEN Data;


//
// set the maximum number of samples that will be composited.
// If a single scanline has more samples, readPixels will throw
// an exception. This mechanism prevents the library allocating
// excessive memory to composite deep scanline images.
// A value of 0 will cause deep compositing to be disabled entirely
// A negative value disables the limit, allowing images with
// arbitrarily large sample counts to be composited
//
IMF_EXPORT
static void setMaximumSampleCount(int64_t sampleCount);

IMF_EXPORT
static int64_t getMaximumSampleCount();


private:
struct Data* _Data;

Expand Down
24 changes: 24 additions & 0 deletions src/lib/OpenEXRUtil/ImfCheckFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Iex.h"
#include "ImfArray.h"
#include "ImfChannelList.h"
#include "ImfCompositeDeepScanLine.h"
#include "ImfCompressor.h"
#include "ImfDeepFrameBuffer.h"
#include "ImfDeepScanLineInputFile.h"
Expand Down Expand Up @@ -1612,9 +1613,22 @@ checkOpenEXRFile (
bool enableCoreCheck)
{
bool threw = false;

uint64_t oldMaxSampleCount = CompositeDeepScanLine::getMaximumSampleCount();

if( reduceMemory || reduceTime)
{
CompositeDeepScanLine::setMaximumSampleCount(1<<20);
}

if (enableCoreCheck)
{
threw = runCoreChecks (fileName, reduceMemory, reduceTime);
}
if (!threw) threw = runChecks (fileName, reduceMemory, reduceTime);

CompositeDeepScanLine::setMaximumSampleCount(oldMaxSampleCount);

return threw;
}

Expand All @@ -1627,13 +1641,23 @@ checkOpenEXRFile (
bool enableCoreCheck)
{
bool threw = false;
uint64_t oldMaxSampleCount = CompositeDeepScanLine::getMaximumSampleCount();

if( reduceMemory || reduceTime)
{
CompositeDeepScanLine::setMaximumSampleCount(1<<20);
}

if (enableCoreCheck)
threw = runCoreChecks (data, numBytes, reduceMemory, reduceTime);
if (!threw)
{
PtrIStream stream (data, numBytes);
threw = runChecks (stream, reduceMemory, reduceTime);
}

CompositeDeepScanLine::setMaximumSampleCount(oldMaxSampleCount);

return threw;
}

Expand Down