fix for buffer-overflow in IPPCalcHistInvoker::operator()

This commit is contained in:
Jan Starzynski 2016-07-06 09:54:28 +02:00
parent b4112a5878
commit 7f896643e9

View File

@ -1188,6 +1188,7 @@ public:
virtual void operator() (const Range & range) const virtual void operator() (const Range & range) const
{ {
Ipp32s levelNum = histSize + 1;
Mat phist(hist->size(), hist->type(), Scalar::all(0)); Mat phist(hist->size(), hist->type(), Scalar::all(0));
#if IPP_VERSION_X100 >= 900 #if IPP_VERSION_X100 >= 900
IppiSize roi = {src->cols, range.end - range.start}; IppiSize roi = {src->cols, range.end - range.start};
@ -1196,7 +1197,7 @@ public:
IppiHistogramSpec *pSpec = NULL; IppiHistogramSpec *pSpec = NULL;
Ipp8u *pBuffer = NULL; Ipp8u *pBuffer = NULL;
if(ippiHistogramGetBufferSize(ipp8u, roi, &histSize, 1, 1, &specSize, &bufferSize) < 0) if(ippiHistogramGetBufferSize(ipp8u, roi, &levelNum, 1, 1, &specSize, &bufferSize) < 0)
{ {
*ok = false; *ok = false;
return; return;
@ -1217,7 +1218,7 @@ public:
return; return;
} }
if(ippiHistogramUniformInit(ipp8u, (Ipp32f*)&low, (Ipp32f*)&high, (Ipp32s*)&histSize, 1, pSpec) < 0) if(ippiHistogramUniformInit(ipp8u, (Ipp32f*)&low, (Ipp32f*)&high, (Ipp32s*)&levelNum, 1, pSpec) < 0)
{ {
if(pSpec) ippFree(pSpec); if(pSpec) ippFree(pSpec);
if(pBuffer) ippFree(pBuffer); if(pBuffer) ippFree(pBuffer);
@ -1233,7 +1234,7 @@ public:
#else #else
CV_SUPPRESS_DEPRECATED_START CV_SUPPRESS_DEPRECATED_START
IppStatus status = ippiHistogramEven_8u_C1R(src->ptr(range.start), (int)src->step, ippiSize(src->cols, range.end - range.start), IppStatus status = ippiHistogramEven_8u_C1R(src->ptr(range.start), (int)src->step, ippiSize(src->cols, range.end - range.start),
phist.ptr<Ipp32s>(), (Ipp32s*)(Ipp32f*)*levels, histSize, (Ipp32s)low, (Ipp32s)high); phist.ptr<Ipp32s>(), (Ipp32s*)(Ipp32f*)*levels, levelNum, (Ipp32s)low, (Ipp32s)high);
CV_SUPPRESS_DEPRECATED_END CV_SUPPRESS_DEPRECATED_END
#endif #endif
if(status < 0) if(status < 0)
@ -1282,7 +1283,7 @@ static bool ipp_calchist(const Mat* images, int nimages, const int* channels,
!accumulate && uniform) !accumulate && uniform)
{ {
ihist.setTo(Scalar::all(0)); ihist.setTo(Scalar::all(0));
AutoBuffer<Ipp32f> levels(histSize[0] + 1); AutoBuffer<Ipp32f> levels(histSize[0]);
bool ok = true; bool ok = true;
const Mat & src = images[0]; const Mat & src = images[0];
@ -1290,7 +1291,7 @@ static bool ipp_calchist(const Mat* images, int nimages, const int* channels,
#ifdef HAVE_CONCURRENCY #ifdef HAVE_CONCURRENCY
nstripes = 1; nstripes = 1;
#endif #endif
IPPCalcHistInvoker invoker(src, ihist, levels, histSize[0] + 1, ranges[0][0], ranges[0][1], &ok); IPPCalcHistInvoker invoker(src, ihist, levels, histSize[0], ranges[0][0], ranges[0][1], &ok);
Range range(0, src.rows); Range range(0, src.rows);
parallel_for_(range, invoker, nstripes); parallel_for_(range, invoker, nstripes);