cvtColor() segfaults in HSV2RGB_f when src has NaNs (Patch #2020)
Description
When the source image has hues which are NaNs, the sector computed by cvFloor (which should be in the range 0 to 5, inclusive) is a large negative number. This sector is used as an offset for an array, and so leads to invalid memory access and a segfault.
This can be fixed by the following patch:
1diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp
2index f887837..ae5ab1f 100644
3--- a/modules/imgproc/src/color.cpp
4+++ b/modules/imgproc/src/color.cpp
5@@ -928,12 +928,15 @@ struct HSV2RGB_f
6 float tab[4];
7 int sector;
8 h *= _hscale;
9+ sector = cvFloor(h);
10+ h -= sector;
11 if( h < 0 )
12 do h += 6; while( h < 0 );
13 else if( h >= 6 )
14 do h -= 6; while( h >= 6 );
15- sector = cvFloor(h);
16- h -= sector;
17+ sector %= 6;
18+ if(sector < 0)
19+ sector += 6;
20
21 tab[0] = v;
22 tab[1] = v*(1.f - s);
Thanks for your time and effort,
Joel.
Related issues
duplicated by Bug #2021: cvtColor() segfaults in HSV2RGB_f when src has NaNs | Cancelled | 2012-06-05 |
Associated revisions
fixed possible access violation in HSV2RGB (patch #2020)
History
Updated by Andrey Kamaev almost 13 years ago
- Tracker changed from Bug to Patch
- Description changed from When the source image has hues which are NaNs, the sector computed by cvFloor... to When the source image has hues which are NaNs, the sector computed by cvFloor... More
Updated by Vadim Pisarevsky over 12 years ago
thanks! the problem is fixed in 9ea5b6
the fix is different from the suggested in order to achieve better efficiency
- Target version set to 2.4.3
- Status changed from Open to Done