Hi,
In surface_matching\src\ppf_match_3d.cpp a function "murmurHash" is used like the following :
KeyType hashKey=0;
murmurHash(key, 4*sizeof(int), 42, &hashKey);
In case of a 64bit system, "murmurHash" is defined via a macro as "hashMurmurx64" in surface_matching\src\hash_murmur.hpp
However this function takes a void* as a parameter which should at least of length (2*sizeof(unsigned int)). Here &hashKey is given, and hashKey is an unsigned int, thus there is a heap corruption.
A workaround consists in forcing "murmurHash" to be defined as hashMurmurx86 even on 32 bit system, but in this case I don't understand the purpose of specific code for x64 systems.
Regards,
Romain
do you have a patch for this?
Those 2 methods are intentional. If they are mixed up, with one alternative the precision of the surface matching drops dramatically, with the other it takes a _lot_ of time.
@rbregier , please reopen this issue if you have reproducing example.
Well, the example program crashes with the example dataset during training:
ppf_load_match.exe parasaurolophus_6700.ply rs1_normals.ply
In debug mode, Visual Studio throws an exception :
In ppf_match_3d.cpp :
And my investigations lead me to the conclusion of my first message.
When asking to Tolga Birdal (the named author in the source code) about it in February, he answered me the following :
"A new version will come out soon hopefully fixing many of the bugs. However, we have tried it on x64 systems, and verified identical results.
As a workaround, you could use hashMurmurx86 on both systems."
My system settings :
Windows 7 64bits
Compiled with Visual Studio 2013 as an x64 executable
So, yes I can provide the fix proposed in my first message, but the resulting performances were not awesome if I remember correctly and according to @bmagyar this fix is suboptimal.
@bmagyar do you have a better solution?
At the time of Tolga's GSoC project, I tested this on all platforms I had available: Ubuntu 32bit, Ubuntu 64bit, OSX 64bit. He was using Windows so it is strange that this didn't come up as well as that no warning about this is reported by buildbot (!).
Frankly, I didn't like that macro magic there in the first place, but at the time that was the best shot. This could be solved by using a hashing library that does the 32/64 switching internally, but I'm also curious to see what Tolga is coming up with.
@tolgabirdal Do you have any thoughts on this?
This might be due to modification made later. Let us define KeyType as follows:
typedef uint64_t KeyType;
typedef unsigned int KeyType;
I will be submitting a pull request with that.
I can confirm that with this definition it runs :
#include <stdint.h>
typedef uint64_t KeyType;
typedef unsigned int KeyType;
However, I get some warnings regarding casts from KeyType to int, unsigned int and size_t. I don't know the effects of those on the algorithm.
How about using KeyType in favor of int in those instances? Could you try that please?
I think it would require a more consequent code refactoring as a default hash function using "unsigned int" (called hash) is used in several place in the code such as for ICP to build hashtables and it is unclear what should be the key type for thoses, but I don't have time to dive into the code and try to figure out how it works in detail. I guess Tolga could fix this easily in his pull request.
In this question same problem exist in opencv-3.2-dev. I replace code as suggested by @tolgabirdal and it works. May be a PR is necessary.
I do have it:
https://github.com/opencv/opencv_contrib/pull/811
But for now seems to have some unsuccessful builds and should be fixed.
@tolgabirdal I have got VS 2013. there is no definition for uint64_t in VS2013 (that's OK in vs2015)
you can try :
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#endif
typedef uint64_t KeyType;
typedef unsigned int KeyType;
you will have some warnings :
1>G:\Lib\opencv_contrib\modules\surface_matching\src\t_hash_int.cpp(122): warning C4244: 'argument' : conversion de 'cv::ppf_match_3d::KeyType' en 'unsigned int', perte possible de données
1>G:\Lib\opencv_contrib\modules\surface_matching\src\t_hash_int.cpp(189): warning C4244: 'argument' : conversion de 'cv::ppf_match_3d::KeyType' en 'unsigned int', perte possible de données
1>G:\Lib\opencv_contrib\modules\surface_matching\src\t_hash_int.cpp(214): warning C4244: 'argument' : conversion de 'cv::ppf_match_3d::KeyType' en 'unsigned int', perte possible de données
1>G:\Lib\opencv_contrib\modules\surface_matching\src\ppf_match_3d.cpp(293): warning C4244: '=' : conversion de 'cv::ppf_match_3d::KeyType' en 'int', perte possible de données
I am using VS 2013 (64 bit)I tried this:
#if (defined x86_64 || defined _M_X64)
#if _MSC_VER <= 1800
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#endif
typedef uint64_t KeyType;
#else
typedef unsigned int KeyType;
#endif
Unfortunately this could not my problem (My problem : Stack around the variable 'hashKey' was corrupted.)
@tolgabirdal @LaurentBerger
@apassenger Did you solve the problem? I have encountered the same problem? still not solved.
My configuration is VS 2013 windows
I am using VS 2015 (64 bit) on a Windows 10 machine with OpenCv 3.2.0 .
I made the changes suggested by @tolgabirdal in the file t_hash_int.hpp where KeyType was defined,
but same runtime error as before which is 'Run-Time Check Failure # 2 - Stack around the variable 'hashKey' was corrupted'.
Any ideas?
Any updates on this? I am using the 3.2 version and get this error with VS2013 x64 aswell
I have added that but the still same problem. openCV 4.0.0, VS -2015
I also tried at opencv 3.4.2
@opencvbel , @apassenger Did you solve that problem?
this problem happend at debug model
at release model processing right, but wrong result
is there any progress on this issue? i meet it using VS2017 and openCV 4.0.0 too.
@JoyMazumder No couldnt find any solution, sorry
Guys,
I have a PR under:
https://github.com/opencv/opencv_contrib/pull/811
This doesn't pass all the tests yet and I do not have the time right now to
update. However, that could hopefully solve this issue.
Cheers,
On Thu, Feb 14, 2019 at 12:18 PM pclbel notifications@github.com wrote:
@JoyMazumder https://github.com/JoyMazumder No couldnt find any
solution, sorry—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/opencv/opencv_contrib/issues/170#issuecomment-463590794,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGqlvfGAPoB0rSDWn9ZufM7528zDAWNEks5vNUYigaJpZM4Dfe5J
.
--
/tolga
I can confirm that with this definition it runs :
if (defined x86_64 || defined _M_X64)
include
typedef uint64_t KeyType;
else
typedef unsigned int KeyType;
endif
However, I get some warnings regarding casts from KeyType to int, unsigned int and size_t. I don't know the effects of those on the algorithm.
It works!However,the performance of the algrithm (after using the changes above)now is quite poor. We cannot even match the samples given in the opencv well.
Very frustrated。。。
In this question same problem exist in opencv-3.2-dev. I replace code as suggested by @tolgabirdal and it works. May be a PR is necessary.
It works!However,the performance of the algrithm (after using the changes above)now is quite poor.
this problem happend at debug model
at release model processing right, but wrong result
It works!However,the performance of the algrithm (after using the changes above)now is quite poor. do you have ideas
any one solve this problem?
Run-Time Check Failure #2 - Stack around the variable 'hashKey' was corrupted.
static KeyType hashPPF(const Vec4d& f, const double AngleStep, const double DistanceStep)
{
Vec4i key(
(int)(f[0] / AngleStep),
(int)(f[1] / AngleStep),
(int)(f[2] / AngleStep),
(int)(f[3] / DistanceStep));
KeyType hashKey = 0;
murmurHash(key.val, 4*sizeof(int), 42, &hashKey);
return hashKey;
}
opencv_4.0.0 x64 vs2017
@luck-boy1994 You using outdated version.
Issue is fixed here: #2347
@ luck-boy1994您使用的是过时的版本。
问题已在此处修复:#2347
thank you
Excuseme ,opencv with new version doesn't have this problem,right?
for example ,opencv 4.0 doesn't have this problem
------------------ 原始邮件 ------------------
发件人: "luck-boy1994"<[email protected]>;
发送时间: 2020年4月19日(星期天) 晚上9:22
收件人: "opencv/opencv_contrib"<[email protected]>;
抄送: "823473780"<[email protected]>;"Comment"<[email protected]>;
主题: Re: [opencv/opencv_contrib] Surface Matching and x64 : heap corruption (#170)
@ luck-boy1994您使用的是过时的版本。
问题已在此处修复:#2347
thank you
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
Most helpful comment
I am using VS 2015 (64 bit) on a Windows 10 machine with OpenCv 3.2.0 .
I made the changes suggested by @tolgabirdal in the file t_hash_int.hpp where KeyType was defined,
but same runtime error as before which is 'Run-Time Check Failure # 2 - Stack around the variable 'hashKey' was corrupted'.
Any ideas?