#include "opencv2/objdetect/objdetect_c.h"
#include "opencl_kernels_objdetect.hpp"
+#if defined(_MSC_VER)
+# pragma warning(disable:4458) // declaration of 'origWinSize' hides class member
+#endif
+
namespace cv
{
//---------------------------------------------- HaarEvaluator ---------------------------------------
-bool HaarEvaluator::Feature :: read( const FileNode& node )
+bool HaarEvaluator::Feature::read(const FileNode& node, const Size& origWinSize)
{
FileNode rnode = node[CC_RECTS];
FileNodeIterator it = rnode.begin(), it_end = rnode.end();
rect[ri].weight = 0.f;
}
+ const int W = origWinSize.width;
+ const int H = origWinSize.height;
+
for(ri = 0; it != it_end; ++it, ri++)
{
FileNodeIterator it2 = (*it).begin();
- it2 >> rect[ri].r.x >> rect[ri].r.y >>
- rect[ri].r.width >> rect[ri].r.height >> rect[ri].weight;
+ Feature::RectWeigth& rw = rect[ri];
+ it2 >> rw.r.x >> rw.r.y >> rw.r.width >> rw.r.height >> rw.weight;
+ // input validation
+ {
+ CV_CheckGE(rw.r.x, 0, "Invalid HAAR feature");
+ CV_CheckGE(rw.r.y, 0, "Invalid HAAR feature");
+ CV_CheckLT(rw.r.x, W, "Invalid HAAR feature"); // necessary for overflow checks
+ CV_CheckLT(rw.r.y, H, "Invalid HAAR feature"); // necessary for overflow checks
+ CV_CheckLE(rw.r.x + rw.r.width, W, "Invalid HAAR feature");
+ CV_CheckLE(rw.r.y + rw.r.height, H, "Invalid HAAR feature");
+ }
}
tilted = (int)node[CC_TILTED] != 0;
for(i = 0; i < n; i++, ++it)
{
- if(!ff[i].read(*it))
+ if(!ff[i].read(*it, _origWinSize))
return false;
if( ff[i].tilted )
hasTiltedFeatures = true;
}
//---------------------------------------------- LBPEvaluator -------------------------------------
-bool LBPEvaluator::Feature :: read(const FileNode& node )
+bool LBPEvaluator::Feature::read(const FileNode& node, const Size& origWinSize)
{
FileNode rnode = node[CC_RECT];
FileNodeIterator it = rnode.begin();
it >> rect.x >> rect.y >> rect.width >> rect.height;
+
+ const int W = origWinSize.width;
+ const int H = origWinSize.height;
+ // input validation
+ {
+ CV_CheckGE(rect.x, 0, "Invalid LBP feature");
+ CV_CheckGE(rect.y, 0, "Invalid LBP feature");
+ CV_CheckLT(rect.x, W, "Invalid LBP feature");
+ CV_CheckLT(rect.y, H, "Invalid LBP feature");
+ CV_CheckLE(rect.x + rect.width, W, "Invalid LBP feature");
+ CV_CheckLE(rect.y + rect.height, H, "Invalid LBP feature");
+ }
+
return true;
}
std::vector<Feature>& ff = *features;
for(int i = 0; it != it_end; ++it, i++)
{
- if(!ff[i].read(*it))
+ if(!ff[i].read(*it, _origWinSize))
return false;
}
nchannels = 1;
origWinSize.width = (int)root[CC_WIDTH];
origWinSize.height = (int)root[CC_HEIGHT];
CV_Assert( origWinSize.height > 0 && origWinSize.width > 0 );
+ CV_CheckLE(origWinSize.width, 1000000, "Invalid window size (too large)");
+ CV_CheckLE(origWinSize.height, 1000000, "Invalid window size (too large)");
// load feature params
FileNode fn = root[CC_FEATURE_PARAMS];