From 2c66e0bbd2de9366b2917c3448012b7907e64028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Wed, 21 Jun 2017 15:03:45 +0300 Subject: [PATCH] Fix warnings about invalid reads in AVX2 ipol AVX2 filter functions read pixels in chunks of 8 or 16 bytes. At the end of the block, the read goes out of the bounds of the pixels array. The extra pixels do not affect the result. Fixes valgrind complaining about the invalid reads by allocating 5 extra pixels in kvz_get_extended_block_avx2 --- src/strategies/avx2/ipol-avx2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/strategies/avx2/ipol-avx2.c b/src/strategies/avx2/ipol-avx2.c index a358c866..2f4614c4 100644 --- a/src/strategies/avx2/ipol-avx2.c +++ b/src/strategies/avx2/ipol-avx2.c @@ -1384,7 +1384,9 @@ void kvz_get_extended_block_avx2(int xpos, int ypos, int mv_x, int mv_y, int off int sample_out_of_bounds = out_of_bounds_y || out_of_bounds_x; if (sample_out_of_bounds){ - out->buffer = MALLOC(kvz_pixel, (width + filter_size) * (height + filter_size)); + // Alloc 5 pixels more than we actually use because AVX2 filter + // functions read up to 5 pixels past the last pixel. + out->buffer = MALLOC(kvz_pixel, (width + filter_size) * (height + filter_size) + 5); if (!out->buffer){ fprintf(stderr, "Memory allocation failed!\n"); assert(0);