hi all
i am using OpenCV 3.4.0 with C++ on Mac OS X. I am trying to access a matrice on a Mat instance like the following:
cv::Mat overlay2 = cv::imread(getAssetsPath() + "overlay.png");
for (int i = 0; i < overlay2.rows; ++i) {
for (int j = 0; j < overlay2.cols; ++j) {
std::cout << i << "x" << j << std::endl;
auto vec = overlay2.at<cv::Vec4f>(i, j);
std::cout << vec << std::endl;
}
}
this is causing me a heap buffer overflow error"
READ of size 4 at 0x00010bed0800 thread T0
#0 0x10003a203 in cv::Matx<float, 4, 1>::Matx(float const*) matx.hpp:665
#1 0x10003a08b in cv::Vec<float, 4>::Vec(cv::Vec<float, 4> const&) matx.hpp:1030
#2 0x10002aa22 in cv::Vec<float, 4>::Vec(cv::Vec<float, 4> const&) matx.hpp:1030
#3 0x100028c6a in OpenCVImage::appendOverlay(OpenCVImage) Image.cpp:32
#4 0x100067434 in testOverlay() main.cpp:45
#5 0x10007762a in main main.cpp:136
#6 0x7fff6b15a114 in start (libdyld.dylib:x86_64+0x1114)
0x00010bed0800 is located 0 bytes to the right of 7077888-byte region [0x00010b810800,0x00010bed0800)
allocated by thread T0 here:
#0 0x1001da830 in wrap_posix_memalign (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x59830)
#1 0x101388d20 in cv::fastMalloc(unsigned long) (libopencv_core.3.4.dylib:x86_64+0x2d20)
#2 0x1014bbc56 in cv::StdMatAllocator::allocate(int, int const*, int, void*, unsigned long*, int, cv::UMatUsageFlags) const (libopencv_core.3.4.dylib:x86_64+0x135c56)
#3 0x10148fece in cv::Mat::create(int, int const*, int) (libopencv_core.3.4.dylib:x86_64+0x109ece)
#4 0x102135c5c in cv::imread_(cv::String const&, int, int, cv::Mat*) (libopencv_imgcodecs.3.4.dylib:x86_64+0x4c5c)
#5 0x10213593f in cv::imread(cv::String const&, int) (libopencv_imgcodecs.3.4.dylib:x86_64+0x493f)
#6 0x100028592 in OpenCVImage::appendOverlay(OpenCVImage) Image.cpp:27
#7 0x100067434 in testOverlay() main.cpp:45
#8 0x10007762a in main main.cpp:136
#9 0x7fff6b15a114 in start (libdyld.dylib:x86_64+0x1114)
SUMMARY: AddressSanitizer: heap-buffer-overflow matx.hpp:665 in cv::Matx<float, 4, 1>::Matx(float const*)
Shadow bytes around the buggy address:
0x1000217da0b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000217da0c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000217da0d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000217da0e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000217da0f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1000217da100:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1000217da110: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1000217da120: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1000217da130: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1000217da140: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x1000217da150: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
2018-02-12 13:26:58.313748+0300 Vivian[79998:4212277] =================================================================
2018-02-12 13:26:58.314180+0300 Vivian[79998:4212277] ==79998==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x00010bed0800 at pc 0x00010003a204 bp 0x7ffeefbfe1e0 sp 0x7ffeefbfe1d8
2018-02-12 13:26:58.314201+0300 Vivian[79998:4212277] READ of size 4 at 0x00010bed0800 thread T0
2018-02-12 13:26:58.314211+0300 Vivian[79998:4212277] #0 0x10003a203 in cv::Matx<float, 4, 1>::Matx(float const*) matx.hpp:665
2018-02-12 13:26:58.314221+0300 Vivian[79998:4212277] #1 0x10003a08b in cv::Vec<float, 4>::Vec(cv::Vec<float, 4> const&) matx.hpp:1030
2018-02-12 13:26:58.314237+0300 Vivian[79998:4212277] #2 0x10002aa22 in cv::Vec<float, 4>::Vec(cv::Vec<float, 4> const&) matx.hpp:1030
2018-02-12 13:26:58.314247+0300 Vivian[79998:4212277] #3 0x100028c6a in OpenCVImage::appendOverlay(OpenCVImage) Image.cpp:32
2018-02-12 13:26:58.314256+0300 Vivian[79998:4212277] #4 0x100067434 in testOverlay() main.cpp:45
2018-02-12 13:26:58.314266+0300 Vivian[79998:4212277] #5 0x10007762a in main main.cpp:136
2018-02-12 13:26:58.314274+0300 Vivian[79998:4212277] #6 0x7fff6b15a114 in start (libdyld.dylib:x86_64+0x1114)
2018-02-12 13:26:58.314413+0300 Vivian[79998:4212277]
2018-02-12 13:26:58.314421+0300 Vivian[79998:4212277] 0x00010bed0800 is located 0 bytes to the right of 7077888-byte region [0x00010b810800,0x00010bed0800)
2018-02-12 13:26:58.314430+0300 Vivian[79998:4212277] allocated by thread T0 here:
2018-02-12 13:26:58.314439+0300 Vivian[79998:4212277] #0 0x1001da830 in wrap_posix_memalign (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x59830)
2018-02-12 13:26:58.314448+0300 Vivian[79998:4212277] #1 0x101388d20 in cv::fastMalloc(unsigned long) (libopencv_core.3.4.dylib:x86_64+0x2d20)
2018-02-12 13:26:58.314457+0300 Vivian[79998:4212277] #2 0x1014bbc56 in cv::StdMatAllocator::allocate(int, int const*, int, void*, unsigned long*, int, cv::UMatUsageFlags) const (libopencv_core.3.4.dylib:x86_64+0x135c56)
2018-02-12 13:26:58.314467+0300 Vivian[79998:4212277] #3 0x10148fece in cv::Mat::create(int, int const*, int) (libopencv_core.3.4.dylib:x86_64+0x109ece)
2018-02-12 13:26:58.314571+0300 Vivian[79998:4212277] #4 0x102135c5c in cv::imread_(cv::String const&, int, int, cv::Mat*) (libopencv_imgcodecs.3.4.dylib:x86_64+0x4c5c)
2018-02-12 13:26:58.314583+0300 Vivian[79998:4212277] #5 0x10213593f in cv::imread(cv::String const&, int) (libopencv_imgcodecs.3.4.dylib:x86_64+0x493f)
2018-02-12 13:26:58.314592+0300 Vivian[79998:4212277] #6 0x100028592 in OpenCVImage::appendOverlay(OpenCVImage) Image.cpp:27
2018-02-12 13:26:58.314601+0300 Vivian[79998:4212277] #7 0x100067434 in testOverlay() main.cpp:45
2018-02-12 13:26:58.314610+0300 Vivian[79998:4212277] #8 0x10007762a in main main.cpp:136
2018-02-12 13:26:58.314618+0300 Vivian[79998:4212277] #9 0x7fff6b15a114 in start (libdyld.dylib:x86_64+0x1114)
2018-02-12 13:26:58.314627+0300 Vivian[79998:4212277]
2018-02-12 13:26:58.314635+0300 Vivian[79998:4212277] SUMMARY: AddressSanitizer: heap-buffer-overflow matx.hpp:665 in cv::Matx<float, 4, 1>::Matx(float const*)
2018-02-12 13:26:58.314714+0300 Vivian[79998:4212277] Shadow bytes around the buggy address:
2018-02-12 13:26:58.314725+0300 Vivian[79998:4212277] 0x1000217da0b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2018-02-12 13:26:58.314734+0300 Vivian[79998:4212277] 0x1000217da0c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2018-02-12 13:26:58.314742+0300 Vivian[79998:4212277] 0x1000217da0d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2018-02-12 13:26:58.314751+0300 Vivian[79998:4212277] 0x1000217da0e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2018-02-12 13:26:58.314760+0300 Vivian[79998:4212277] 0x1000217da0f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2018-02-12 13:26:58.314803+0300 Vivian[79998:4212277] =>0x1000217da100:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2018-02-12 13:26:58.314815+0300 Vivian[79998:4212277] 0x1000217da110: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2018-02-12 13:26:58.314865+0300 Vivian[79998:4212277] 0x1000217da120: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2018-02-12 13:26:58.314885+0300 Vivian[79998:4212277] 0x1000217da130: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2018-02-12 13:26:58.314923+0300 Vivian[79998:4212277] 0x1000217da140: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2018-02-12 13:26:58.314937+0300 Vivian[79998:4212277] 0x1000217da150: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
2018-02-12 13:26:58.314947+0300 Vivian[79998:4212277] Shadow byte legend (one shadow byte represents 8 application bytes):
2018-02-12 13:26:58.314957+0300 Vivian[79998:4212277] Addressable: 00
2018-02-12 13:26:58.314966+0300 Vivian[79998:4212277] Partially addressable: 01 02 03 04 05 06 07
2018-02-12 13:26:58.314975+0300 Vivian[79998:4212277] Heap left redzone: fa
2018-02-12 13:26:58.314983+0300 Vivian[79998:4212277] Freed heap region: fd
2018-02-12 13:26:58.314991+0300 Vivian[79998:4212277] Stack left redzone: f1
2018-02-12 13:26:58.315073+0300 Vivian[79998:4212277] Stack mid redzone: f2
2018-02-12 13:26:58.315102+0300 Vivian[79998:4212277] Stack right redzone: f3
2018-02-12 13:26:58.315119+0300 Vivian[79998:4212277] Stack after return: f5
2018-02-12 13:26:58.315129+0300 Vivian[79998:4212277] Stack use after scope: f8
2018-02-12 13:26:58.315137+0300 Vivian[79998:4212277] Global redzone: f9
2018-02-12 13:26:58.315145+0300 Vivian[79998:4212277] Global init order: f6
2018-02-12 13:26:58.315153+0300 Vivian[79998:4212277] Poisoned by user: f7
2018-02-12 13:26:58.315161+0300 Vivian[79998:4212277] Container overflow: fc
2018-02-12 13:26:58.315169+0300 Vivian[79998:4212277] Array cookie: ac
2018-02-12 13:26:58.315178+0300 Vivian[79998:4212277] Intra object redzone: bb
2018-02-12 13:26:58.315186+0300 Vivian[79998:4212277] ASan internal: fe
2018-02-12 13:26:58.315195+0300 Vivian[79998:4212277] Left alloca redzone: ca
2018-02-12 13:26:58.315222+0300 Vivian[79998:4212277] Right alloca redzone: cb
2018-02-12 13:26:58.315237+0300 Vivian[79998:4212277]
==79998==ABORTING
AddressSanitizer report breakpoint hit. Use 'thread info -s' to get extended information about the report.
how can i fix this problem?