From d7a735400aa5fa6dc30da9cb891570f036850255 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sat, 6 Jun 2020 14:50:32 +0200 Subject: [PATCH] reducev: Fix undefined-behaviour within the vector path Found by UBSan. --- libvips/resample/reducev.cpp | 5 ++--- test/test-suite/test_resample.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libvips/resample/reducev.cpp b/libvips/resample/reducev.cpp index fa965134..396069f2 100644 --- a/libvips/resample/reducev.cpp +++ b/libvips/resample/reducev.cpp @@ -653,10 +653,9 @@ vips_reducev_vector_gen( VipsRegion *out_region, void *vseq, #endif /*DEBUG_PIXELS*/ s.left = r->left; - s.top = r->top * reducev->vshrink; + s.top = r->top * reducev->vshrink - reducev->voffset; s.width = r->width; - s.height = r->height * reducev->vshrink + reducev->n_point - - reducev->voffset; + s.height = r->height * reducev->vshrink + reducev->n_point; if( vips_region_prepare( ir, &s ) ) return( -1 ); diff --git a/test/test-suite/test_resample.py b/test/test-suite/test_resample.py index 6453d62e..04c81580 100644 --- a/test/test-suite/test_resample.py +++ b/test/test-suite/test_resample.py @@ -82,9 +82,8 @@ class TestResample: for fac in [1, 1.1, 1.5, 1.999]: for fmt in all_formats: - # TODO: Add nearest kernel when https://github.com/libvips/libvips/issues/1518 is done. - # (running the test suite with VIPS_NOVECTOR=1 should also work) - for kernel in ["linear", "cubic", "lanczos2", "lanczos3"]: + for kernel in ["nearest", "linear", + "cubic", "lanczos2", "lanczos3"]: x = im.cast(fmt) r = x.reduce(fac, fac, kernel=kernel) d = abs(r.avg() - im.avg())