From e212b8f0bf58a9eca6ba164a8f900f245b4839b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Sat, 14 Jan 2023 17:14:36 +0800 Subject: [PATCH] Add parameter check to copy{Into,From}FrameBuffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡玮文 --- src/lib/OpenEXR/ImfMisc.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/lib/OpenEXR/ImfMisc.cpp b/src/lib/OpenEXR/ImfMisc.cpp index be755b0ae8..e9e034300d 100644 --- a/src/lib/OpenEXR/ImfMisc.cpp +++ b/src/lib/OpenEXR/ImfMisc.cpp @@ -22,6 +22,7 @@ #include #include #include +#include OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER @@ -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) { // @@ -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.