From 118d8106640796d3f2ceb55f8634a32a58a47aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 15 Oct 2024 05:34:55 +0200 Subject: [PATCH] shaders/sampling: fill the lut padding This ensures that we don't interpolate lut values with garbage values when row_size is not multiple of 4. Avoid UB that produces incorrect values. This commit fixes the fast path of orthogonal scaling. Fixes: https://github.com/mpv-player/mpv/issues/13998 --- src/shaders/sampling.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/shaders/sampling.c b/src/shaders/sampling.c index e7bddaf2..e49b5295 100644 --- a/src/shaders/sampling.c +++ b/src/shaders/sampling.c @@ -919,12 +919,16 @@ static void fill_ortho_lut(void *data, const struct sh_lut_params *params) const float *weights = filt->weights + n * filt->row_stride; float *row = (float *) data + n * filt->row_stride; pl_assert(filt->row_size % 2 == 0); - for (int i = 0; i < filt->row_size; i += 2) { + int i = 0; + for (; i < filt->row_size; i += 2) { const float w0 = weights[i], w1 = weights[i+1]; assert(w0 + w1 >= 0.0f); row[i] = w0 + w1; row[i+1] = w1 / (w0 + w1); } + pl_assert(filt->params.row_stride_align == 4); // always 4 components + for (; i < filt->row_stride; i++) + row[i] = i >= 4 ? row[i - 4] : 0; } } else { size_t entries = SCALER_LUT_SIZE * filt->row_stride;