Commit 184b6e31 authored by Yan Wang's avatar Yan Wang

Fix canny segment fault (Bug #3978)

Avoid stack overflow based on std::vector cause
std::vector::resize() segmentation fault.
parent 4f2aeeff
...@@ -453,7 +453,7 @@ void cv::Canny( InputArray _src, OutputArray _dst, ...@@ -453,7 +453,7 @@ void cv::Canny( InputArray _src, OutputArray _dst,
if ((stack_top - stack_bottom) + src.cols > maxsize) if ((stack_top - stack_bottom) + src.cols > maxsize)
{ {
int sz = (int)(stack_top - stack_bottom); int sz = (int)(stack_top - stack_bottom);
maxsize = maxsize * 3/2; maxsize = std::max(maxsize * 3/2, sz + src.cols);
stack.resize(maxsize); stack.resize(maxsize);
stack_bottom = &stack[0]; stack_bottom = &stack[0];
stack_top = stack_bottom + sz; stack_top = stack_bottom + sz;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment