Skip to content

Commit e212b8f

Browse files
committed
Add parameter check to copy{Into,From}FrameBuffer
Signed-off-by: 胡玮文 <[email protected]>
1 parent 55bdfd1 commit e212b8f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/lib/OpenEXR/ImfMisc.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <ImfStdIO.h>
2323
#include <ImfTileDescription.h>
2424
#include <ImfXdr.h>
25+
#include <cassert>
2526

2627
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
2728

@@ -275,6 +276,20 @@ copyIntoFrameBuffer (
275276
//
276277
endPtr += xStride;
277278

279+
if (xStride == 0)
280+
{
281+
throw IEX_NAMESPACE::ArgExc ("Zero stride is invalid.");
282+
}
283+
if ((endPtr - writePtr) / xStride <= 0)
284+
{
285+
// Nothing to do, the specified range is empty.
286+
return;
287+
}
288+
if ((endPtr - writePtr) % xStride != 0)
289+
{
290+
throw IEX_NAMESPACE::ArgExc ("Stride will not exactly span input data.");
291+
}
292+
278293
if (fill)
279294
{
280295
//
@@ -1533,6 +1548,21 @@ copyFromFrameBuffer (
15331548
char* localWritePtr = writePtr;
15341549
const char* localReadPtr = readPtr;
15351550
endPtr += xStride;
1551+
1552+
if (xStride == 0)
1553+
{
1554+
throw IEX_NAMESPACE::ArgExc ("Zero stride is invalid.");
1555+
}
1556+
if ((endPtr - localReadPtr) / xStride <= 0)
1557+
{
1558+
// Nothing to do, the specified range is empty.
1559+
return;
1560+
}
1561+
if ((endPtr - localReadPtr) % xStride != 0)
1562+
{
1563+
throw IEX_NAMESPACE::ArgExc ("Stride will not exactly span input data.");
1564+
}
1565+
15361566
//
15371567
// Copy a horizontal row of pixels from a frame
15381568
// buffer to an output file's line or tile buffer.

0 commit comments

Comments
 (0)