Ask Your Question
0

ellipse() bug found!

asked 2014-02-13 02:03:35 -0600

mfeinstein gravatar image

updated 2014-02-13 02:04:55 -0600

I am using OpenCV 2.4.6, I cant test it in the most recent versions, so I thougt it will be just better to place it in here...I am sorry if this was already corrected in the most recent ones.

If I call ellipse() as:

ellipse(image, RotatedRect(Point2f(-78877.320,-79104.328),Size2f(1.0649987e-010f,3.1949962e-010f),0.0f), CV_RGB(255, 0, 0), 1, 8); // OpenCV Bug discovered!

being image a 640x480 image, my program crashes.

ellipse() calls EllipeseEx() who calls ellipse2Poly() who crashes.

ellipse() does:

Point center(cvRound(box.center.x*(1 << XY_SHIFT)), cvRound(box.center.y*(1 << XY_SHIFT)));

which makes center.x and center.y equals to INT_MIN. this way ellipse2Poly() crashes when it tries in it's last line to acessa an empty vector [0] position in:

if( pts.size() < 2 )
        pts.push_back(pts[0]);

since for this case

if( pt != prevPt )
            pts.push_back(pt);

Is never != so the push_back() is never executed.

The code should be changed to

if( pts.size() < 2  && pts.size() > 0 )
        pts.push_back(pts[0]);

So this way, the vector will be never acessed in case it's empty, crashing the program.

I am sorry to not submit this to the repository myself, I just can't upload that code right now.

edit retag flag offensive close merge delete

Comments

usually, you'd do a small test case, and go here

and ofc., ayou should check the src code for the 2.4 branch to see if it got fixed in the meantime

berak gravatar imageberak ( 2014-02-13 02:17:15 -0600 )edit

I know, I just cant do it right now...can you check this for me?

mfeinstein gravatar imagemfeinstein ( 2014-02-18 01:32:26 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-02-18 01:41:20 -0600

mfeinstein gravatar image

It was already fixed in the new version, sorry for this.

edit flag offensive delete link more

Comments

Well I cant accept my own answer, so if someone places one like this I will accept

mfeinstein gravatar imagemfeinstein ( 2014-02-18 01:42:15 -0600 )edit

anyway, nice, that you reported back ;)

berak gravatar imageberak ( 2014-02-18 08:15:38 -0600 )edit

Thanks, now there is just a weird behaviour I get in findContours() when I compile it as release...it does a stackoverlow....I cant debug it since it's release, but removing findContours() makes the program run nicely...maybe its a bug in the dll? I wish I could foward this to someone more expert than me to analise it further....but I dont know anyone :/

mfeinstein gravatar imagemfeinstein ( 2014-02-18 21:25:38 -0600 )edit

Question Tools

Stats

Asked: 2014-02-13 02:03:35 -0600

Seen: 366 times

Last updated: Feb 18 '14