dthuerck / mapmap_cpu

A high-performance general-purpose MRF MAP solver, heavily exploiting SIMD instructions.
BSD 3-Clause "New" or "Revised" License
102 stars 51 forks source link

Invalid write #1

Closed nmoehrle closed 7 years ago

nmoehrle commented 7 years ago

There is an invalid write in multilevel.impl.h:819.

The vector costs has only size num_labels * num_labels_chunk but is addressed at i * num_labels + j where both i and j are in [0, num_labels_chunk).

==24050== Invalid write of size 8
==24050==    at 0x4BFDF0: _mm_storeu_ps (xmmintrin.h:980)
==24050==    by 0x4BFDF0: v_store<float, 4u> (vector_math.impl.h:851)
==24050==    by 0x4BFDF0: compute_level_pairwise (multilevel.impl.h:819)
==24050==    by 0x4BFDF0: next_level (multilevel.impl.h:211)
==24050==    by 0x4BFDF0: opt_step_multilevel (mapmap.impl.h:527)
==24050==    by 0x4BFDF0: optimize (mapmap.impl.h:260)
==24050==    by 0x4BFDF0: tex::view_selection(SparseTable<unsigned int, unsigned short, float> const&, UniGraph*, tex::Settings const&) (view_selection.cpp:90)
==24050==    by 0x457C5B: main (texrecon.cpp:98)
dthuerck commented 7 years ago

Hi,

thanks for noticing the bug and opening this issue! Should be fixed with e9aa317b20055deb3990e60629b2c9090128bc7a, now.

You're right, i should only iterate until num_labels, though j's bounds are correct. In the inner loop, invalid labels (these between num_labels and num_labels_chunked) need to be masked out, e.g. replaced by 0. I added that.