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

Git pushed a commit to branch master
in repository ffmpeg.

commit 5c661dec6187e6e4a4dd80a9cad551ea202df407
Author:     Niklas Haas <[email protected]>
AuthorDate: Fri Feb 20 16:02:32 2026 +0100
Commit:     Niklas Haas <[email protected]>
CommitDate: Sat Feb 21 11:47:43 2026 +0000

    swscale/ops: avoid UB in ff_sws_pixel_expand()
    
    Restructure the loop slightly to avoid UB in the first loop iteration if
    src is 4 bytes, which otherwise computes (0 << 32) | 1. Instead, make
    1 the default base case and only shift+add if src < dst.
    
    Add an explicit check to preserve the behavior of returnin 0 if src > dst.
---
 libswscale/ops_internal.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libswscale/ops_internal.h b/libswscale/ops_internal.h
index ba4c9b39da..e8d059a6d0 100644
--- a/libswscale/ops_internal.h
+++ b/libswscale/ops_internal.h
@@ -31,9 +31,11 @@ static inline AVRational ff_sws_pixel_expand(SwsPixelType 
from, SwsPixelType to)
 {
     const int src = ff_sws_pixel_type_size(from);
     const int dst = ff_sws_pixel_type_size(to);
-    int scale = 0;
-    for (int i = 0; i < dst / src; i++)
-        scale = scale << src * 8 | 1;
+    if (src > dst)
+        return Q(0);
+    int scale = 1;
+    for (int i = 1; i < dst / src; i++)
+        scale = (scale << (src * 8)) | 1;
     return Q(scale);
 }
 

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to