Big matrix Mat::isContinuous() error on 64-bit systems (Patch #2103)


Added by Boris Mansencal over 12 years ago. Updated over 12 years ago.


Status:Done Start date:2012-06-27
Priority:Normal Due date:
Assignee:Andrey Kamaev % Done:

0%

Category:core
Target version:2.4.2
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

Mat::isContinuous() gives an erroneous result on 64-bit systems.

The attached file testBigMat.cpp checks whether Mat::isContinuous() gives the same result than myCheckMatContinuity() function defined in the documentation, here:
http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-iscontinuous
It tries to allocate a big matrix (you need a machine with 16Go of memory to test it).

On Windows 7, with Visual C++ 2010 Express, compiled in 32-bit and linked with precompiled OpenCV 2.4.1 (ia32),
it gives the following error message:

"OpenCV Error: One of arguments' values is out of range (The total matrix size does not fit to "size_t" type) in unknown function, 
file C:\slave\WinInstallerMegaPack\src\opencv\modules\core\src\matrix.cpp, line 125" 
This is ok (as size_t is 32bits here).

On linux (Fedora 14 x86_64), with g++ 4.5.1, compiled in 64-bit and linked with OpenCV 2.3.1 & 2.4.1 compiled in 64-bit,
I get no error (size_t is 64bits here) however the created matrix is marked as not continuous.
This is not ok.

This is problematic as other methods depend on this check (Mat::reshape() for example).

I have found that there is the following test :
if( j <= i && t (int)t )
in modules/core/src/matrix.cpp: updateContinuityFlag(Mat& m)
I don't totally understand why there is this test "t (int)t", but changing it to "t == (size_t)t" might solve the problem.
This is what the patch bigMat.patch does.

On linux 64-bit, the test is now ok: the allocated big matrix is continuous (with OpenCV 2.3.1 & 2.4.1).
I believe this patch will not change the behavior on Windows in 32-bit as size_t is 32-bit there... but I have not tested.


testBigMat.cpp - check Mat::isContinuous() gives the same result than myCheckMatContinuity() defined in documentation (1.3 kB) Boris Mansencal, 2012-06-27 03:26 pm

bigMat.patch - change test "t == (int)t" in "t == (size_t)t" in updateContinuityFlag() in matrix.cpp (691 Bytes) Boris Mansencal, 2012-06-27 03:26 pm


Associated revisions

Revision f09ae327
Added by Andrey Kamaev over 12 years ago

Fixed Mat::isContinuous for big matrix (thanks to Boris Mansencal) #2103

Revision ea3dd9d5
Added by Roman Donchenko about 11 years ago

Merge pull request #2103 from ilya-lavrenov:typo

History

Updated by Andrey Kamaev over 12 years ago

Thanks, your patch is applied.

  • Tracker changed from Bug to Patch
  • Status changed from Open to Done
  • Priority changed from High to Normal
  • Target version set to 2.4.2
  • Description changed from Mat::isContinuous() gives an erroneous result on 64-bit systems. The attache... to @Mat::isContinuous()@ gives an erroneous result on 64-bit systems. The attac... More
  • Assignee changed from Vadim Pisarevsky to Andrey Kamaev

Also available in: Atom PDF