Skip to content

Commit

Permalink
Add parameter check to copy{Into,From}FrameBuffer
Browse files Browse the repository at this point in the history
Signed-off-by: 胡玮文 <[email protected]>
  • Loading branch information
huww98 committed Jan 19, 2023
1 parent 23e7270 commit 785c1fa
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/lib/OpenEXR/ImfMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ImfStdIO.h>
#include <ImfTileDescription.h>
#include <ImfXdr.h>
#include <cassert>

OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER

Expand Down Expand Up @@ -275,6 +276,20 @@ copyIntoFrameBuffer (
//
endPtr += xStride;

if (xStride == 0)
{
throw IEX_NAMESPACE::ArgExc ("Zero stride is invalid.");
}
if ((endPtr - writePtr) / xStride <= 0)
{
// Nothing to do, the specified range is empty.
return;
}
if ((endPtr - writePtr) % xStride != 0)
{
throw IEX_NAMESPACE::ArgExc ("Stride will not exactly span input data.");
}

if (fill)
{
//
Expand Down Expand Up @@ -1533,6 +1548,21 @@ copyFromFrameBuffer (
char* localWritePtr = writePtr;
const char* localReadPtr = readPtr;
endPtr += xStride;

if (xStride == 0)
{
throw IEX_NAMESPACE::ArgExc ("Zero stride is invalid.");
}
if ((endPtr - localReadPtr) / xStride <= 0)
{
// Nothing to do, the specified range is empty.
return;
}
if ((endPtr - localReadPtr) % xStride != 0)
{
throw IEX_NAMESPACE::ArgExc ("Stride will not exactly span input data.");
}

//
// Copy a horizontal row of pixels from a frame
// buffer to an output file's line or tile buffer.
Expand Down

0 comments on commit 785c1fa

Please sign in to comment.