ermig1979 / Simd

C++ image processing and machine learning library with using of SIMD: SSE, AVX, AVX-512, AMX for x86/x64, VMX(Altivec) and VSX(Power7) for PowerPC, NEON for ARM.
http://ermig1979.github.io/Simd
MIT License
2.04k stars 407 forks source link

Segmentation fault with Simd::Resize #110

Closed s-trinh closed 4 years ago

s-trinh commented 4 years ago

I have a segmentation fault with the following code:

    const int width = 64, height = 48;
    std::vector<unsigned char> buffer_src(width*height);
    std::fill(buffer_src.begin(), buffer_src.end(), 0);

    typedef Simd::View<Simd::Allocator> View;
    View src(width, height, width, View::Gray8, buffer_src.data());

    const int width_resize = 11, height_resize = 17;
    std::vector<unsigned char> buffer_dst(width_resize*height_resize);
    View dst(width_resize, height_resize, width_resize, View::Gray8, buffer_dst.data());

    Simd::Resize(src, dst, SimdResizeMethodBilinear);

The stack trace:

    Program received signal SIGSEGV, Segmentation fault.
    Simd::Sse2::ResizerByteBilinearInterpolateY<false>(unsigned char const*, unsigned char const*, long long __vector(2)*, unsigned char*) (
        dst=0x800000000061994b <error: Cannot access memory at address 0x800000000061994b>,
        alpha=<synthetic pointer>, bx1=0x61a0f6 "", bx0=0x619ff6 "")
        at Simd/SimdSse2Resizer.cpp:114
    114             Store<false>((__m128i*)dst, _mm_packus_epi16(lo, hi));
    (gdb) bt
    #0  Simd::Sse2::ResizerByteBilinearInterpolateY<false>(unsigned char const*, unsigned char const*, long long __vector(2)*, unsigned char*) (
        dst=0x800000000061994b <error: Cannot access memory at address 0x800000000061994b>,
        alpha=<synthetic pointer>, bx1=0x61a0f6 "", bx0=0x619ff6 "")
        at Simd/SimdSse2Resizer.cpp:114
    #1  Simd::Sse2::ResizerByteBilinear::Run<1ul> (this=0x619a20, src=<optimized out>, srcStride=64,
        dst=0x619950 "", dstStride=<optimized out>)
        at Simd/SimdSse2Resizer.cpp:166
    #2  0x0000000000400b0e in Simd::Resize<Simd::Allocator> (method=SimdResizeMethodBilinear,
        dst=<synthetic pointer>...,
        src=<error reading variable: access outside bounds of object referenced via synthetic pointer>)
        at Simd/SimdLib.hpp:2842
    #3  main (argc=<optimized out>, argv=<optimized out>)
ermig1979 commented 4 years ago

Thank you for bug report. I will try to reproduce this error tomorrow.

ermig1979 commented 4 years ago

The error was reproduced and fixed.