This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit c6af16b048a4ba2edc8be5205dbe12aa4df2d26a
Author:     Michael Niedermayer <[email protected]>
AuthorDate: Wed Nov 11 21:17:27 2026 +0100
Commit:     michaelni <[email protected]>
CommitDate: Wed Nov 18 23:19:07 2026 +0000

    swscale/x86/yuv2rgb: do not write past the width in the SSSE3 converters
    
    Fixes: out of array write
    Fixes: v6YVGm0pHn7P
    Out of array write Replicated through API with Valgrind
    
    Found during triage of the security report bKTdZBAokzK8
---
 libswscale/x86/yuv2rgb.c     | 36 +++++++++++++++++++++++++++++-------
 libswscale/x86/yuv_2_rgb.asm | 15 ++++++++++++++-
 2 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/libswscale/x86/yuv2rgb.c b/libswscale/x86/yuv2rgb.c
index 2291c84e53..b49c93edf7 100644
--- a/libswscale/x86/yuv2rgb.c
+++ b/libswscale/x86/yuv2rgb.c
@@ -41,9 +41,7 @@
 #if HAVE_X86ASM
 
 #define YUV2RGB_LOOP(depth)                                          \
-    h_size = (c->opts.dst_w + 7) & ~7;                               \
-    if (h_size * depth > FFABS(dstStride[0]))                        \
-        h_size -= 8;                                                 \
+    h_size = c->opts.dst_w;                                          \
                                                                      \
     vshift = c->opts.src_format != AV_PIX_FMT_YUV422P;               \
                                                                      \
@@ -54,6 +52,15 @@
         const uint8_t *pv = src[2] +   (y >> vshift) * srcStride[2]; \
         x86_reg index = -h_size / 2;                                 \
 
+#define YUV2RGB_ODD_PIXEL(depth, convert, ...)                       \
+    if (h_size & 1) {                                                \
+        uint8_t block[16 * depth];                                   \
+        convert(-8, block, pu - index + 1, pv - index + 1,           \
+                &(c->redDither), __VA_ARGS__);                       \
+        memcpy(image + (h_size - 1) * depth, block + 14 * depth,     \
+               depth);                                               \
+    }
+
 extern void ff_yuv_420_rgb24_ssse3(x86_reg index, uint8_t *image, const 
uint8_t *pu_index,
                                    const uint8_t *pv_index, const uint64_t 
*pointer_c_dither,
                                    const uint8_t *py_2index);
@@ -100,6 +107,7 @@ static inline int yuv420_rgb15_ssse3(SwsInternal *c, const 
uint8_t *const src[],
         c->redDither   = ff_dither8[(y + 1) & 1];
 
         ff_yuv_420_rgb15_ssse3(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
+        YUV2RGB_ODD_PIXEL(2, ff_yuv_420_rgb15_ssse3, py - 2 * index + 2)
     }
     return srcSliceH;
 }
@@ -118,6 +126,7 @@ static inline int yuv420_rgb16_ssse3(SwsInternal *c, const 
uint8_t *const src[],
         c->redDither   = ff_dither8[(y + 1) & 1];
 
         ff_yuv_420_rgb16_ssse3(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
+        YUV2RGB_ODD_PIXEL(2, ff_yuv_420_rgb16_ssse3, py - 2 * index + 2)
     }
     return srcSliceH;
 }
@@ -132,6 +141,7 @@ static inline int yuv420_rgb32_ssse3(SwsInternal *c, const 
uint8_t *const src[],
     YUV2RGB_LOOP(4)
 
         ff_yuv_420_rgb32_ssse3(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
+        YUV2RGB_ODD_PIXEL(4, ff_yuv_420_rgb32_ssse3, py - 2 * index + 2)
     }
     return srcSliceH;
 }
@@ -146,6 +156,7 @@ static inline int yuv420_bgr32_ssse3(SwsInternal *c, const 
uint8_t *const src[],
     YUV2RGB_LOOP(4)
 
         ff_yuv_420_bgr32_ssse3(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
+        YUV2RGB_ODD_PIXEL(4, ff_yuv_420_bgr32_ssse3, py - 2 * index + 2)
     }
     return srcSliceH;
 }
@@ -160,6 +171,7 @@ static inline int yuva420_rgb32_ssse3(SwsInternal *c, const 
uint8_t *const src[]
 
         const uint8_t *pa = src[3] + y * srcStride[3];
         ff_yuva_420_rgb32_ssse3(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index, pa - 2 * index);
+        YUV2RGB_ODD_PIXEL(4, ff_yuva_420_rgb32_ssse3, py - 2 * index + 2, pa - 
2 * index + 2)
     }
     return srcSliceH;
 }
@@ -175,6 +187,7 @@ static inline int yuva420_bgr32_ssse3(SwsInternal *c, const 
uint8_t *const src[]
 
         const uint8_t *pa = src[3] + y * srcStride[3];
         ff_yuva_420_bgr32_ssse3(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index, pa - 2 * index);
+        YUV2RGB_ODD_PIXEL(4, ff_yuva_420_bgr32_ssse3, py - 2 * index + 2, pa - 
2 * index + 2)
     }
     return srcSliceH;
 }
@@ -189,6 +202,7 @@ static inline int yuv420_rgb24_ssse3(SwsInternal *c, const 
uint8_t *const src[],
     YUV2RGB_LOOP(3)
 
         ff_yuv_420_rgb24_ssse3(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
+        YUV2RGB_ODD_PIXEL(3, ff_yuv_420_rgb24_ssse3, py - 2 * index + 2)
     }
     return srcSliceH;
 }
@@ -203,6 +217,7 @@ static inline int yuv420_bgr24_ssse3(SwsInternal *c, const 
uint8_t *const src[],
     YUV2RGB_LOOP(3)
 
         ff_yuv_420_bgr24_ssse3(index, image, pu - index, pv - index, 
&(c->redDither), py - 2 * index);
+        YUV2RGB_ODD_PIXEL(3, ff_yuv_420_bgr24_ssse3, py - 2 * index + 2)
     }
     return srcSliceH;
 }
@@ -215,9 +230,7 @@ static inline int yuv420_gbrp_ssse3(SwsInternal *c, const 
uint8_t *const src[],
 {
     int y, h_size, vshift;
 
-    h_size = (c->opts.dst_w + 7) & ~7;
-    if (h_size > FFABS(dstStride[0]))
-        h_size -= 8;
+    h_size = c->opts.dst_w;
 
     vshift = c->opts.src_format != AV_PIX_FMT_YUV422P;
 
@@ -231,6 +244,14 @@ static inline int yuv420_gbrp_ssse3(SwsInternal *c, const 
uint8_t *const src[],
         x86_reg index = -h_size / 2;
 
         ff_yuv_420_gbrp24_ssse3(index, dst_g, dst_b, dst_r, pu - index, pv - 
index, &(c->redDither), py - 2 * index);
+        if (h_size & 1) {
+            uint8_t block[3][16];
+            ff_yuv_420_gbrp24_ssse3(-8, block[0], block[1], block[2], pu - 
index + 1, pv - index + 1,
+                                    &(c->redDither), py - 2 * index + 2);
+            dst_g[h_size - 1] = block[0][14];
+            dst_b[h_size - 1] = block[1][14];
+            dst_r[h_size - 1] = block[2][14];
+        }
     }
     return srcSliceH;
 }
@@ -243,7 +264,8 @@ av_cold SwsFunc ff_yuv2rgb_init_x86(SwsInternal *c)
 #if HAVE_X86ASM
     int cpu_flags = av_get_cpu_flags();
 
-    if (EXTERNAL_SSSE3(cpu_flags)) {
+    /* the converters need at least one block of 16 pixels */
+    if (EXTERNAL_SSSE3(cpu_flags) && c->opts.dst_w >= 16) {
         switch (c->opts.dst_format) {
         case AV_PIX_FMT_RGB32:
             if (c->opts.src_format == AV_PIX_FMT_YUVA420P) {
diff --git a/libswscale/x86/yuv_2_rgb.asm b/libswscale/x86/yuv_2_rgb.asm
index eeb1d25942..353a2e21ca 100644
--- a/libswscale/x86/yuv_2_rgb.asm
+++ b/libswscale/x86/yuv_2_rgb.asm
@@ -296,8 +296,21 @@ cglobal %1_420_%2%3, GPR_num, GPR_num, reg_num, parameters
 
 add imageq, 8 * depth * time_num
 add indexq, 4 * time_num
-js .loop0
+jns .end
+cmp indexq, -4 * time_num
+jle .loop0
+; less than a block is left, convert the last block of the row
+add indexq, 4 * time_num
+imul indexq, 2 * depth
+sub imageq, indexq
+%ifidn %2, gbrp
+sub dst_bq, indexq
+sub dst_rq, indexq
+%endif
+mov indexq, -4 * time_num
+jmp .loop0
 
+.end:
 RET
 
 %endmacro

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to