PR #22593 opened by MarcosAsh
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22593
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22593.patch

Fixes #22276.

The DEFINE_REMAP macro has a loop condition with a precedence bug:

     ` for (int stereo = 0; stereo < 1 + s->out_stereo > STEREO_2D; stereo++)`

Because `<` and `>` associate left-to-right at the same precedence level, this 
parses as `(stereo < (1 + s->out_stereo)) > STEREO_2D`. Since STEREO_2D is 0, 
the outer `> 0` comparison is effectively a no-op for STEREO_2D and STEREO_SBS. 
But for STEREO_TB (value 2) the loop runs 3 iterations instead of 2, producing 
an out-of-bounds stereo pass.

The fix adds parentheses so the intent is clear:

      `for (int stereo = 0; stereo < 1 + (s->out_stereo > STEREO_2D); stereo++)`

This gives 1 iteration for 2D and 2 for any stereo format, matching the number 
of actual stereo views.

Recent Clang versions (21.x) flag this without -Wno-parentheses, which is how 
the issue was reported.


>From 249409d1fbaa9a9c9e8af682551802c4046d9acd Mon Sep 17 00:00:00 2001
From: marcos ashton <[email protected]>
Date: Mon, 23 Mar 2026 14:08:35 +0000
Subject: [PATCH] libavfilter/vf_v360: fix operator precedence in stereo loop
 condition

The loop condition in the DEFINE_REMAP macro:

  stereo < 1 + s->out_stereo > STEREO_2D

is parsed by C as:

  (stereo < (1 + s->out_stereo)) > STEREO_2D

Since STEREO_2D is 0 and relational operators return 0 or 1, the
outer comparison against 0 is a no-op for STEREO_2D and STEREO_SBS.
But for STEREO_TB (value 2) the loop runs 3 iterations instead of 2,
producing an out-of-bounds stereo pass.

Add parentheses so the comparison is evaluated first:

  stereo < 1 + (s->out_stereo > STEREO_2D)

This gives 1 iteration for 2D and 2 for any stereo format (SBS or TB),
matching the actual number of stereo views.

Signed-off-by: marcos ashton <[email protected]>
---
 libavfilter/vf_v360.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c
index a5297c81e9..a08279867f 100644
--- a/libavfilter/vf_v360.c
+++ b/libavfilter/vf_v360.c
@@ -291,7 +291,7 @@ static int remap##ws##_##bits##bit_slice(AVFilterContext 
*ctx, void *arg, int jo
                                                                                
                            \
     av_assert1(s->nb_planes <= AV_VIDEO_MAX_PLANES);                           
                            \
                                                                                
                            \
-    for (int stereo = 0; stereo < 1 + s->out_stereo > STEREO_2D; stereo++) {   
                            \
+    for (int stereo = 0; stereo < 1 + (s->out_stereo > STEREO_2D); stereo++) { 
                              \
         for (int plane = 0; plane < s->nb_planes; plane++) {                   
                            \
             const unsigned map = s->map[plane];                                
                            \
             const int in_linesize  = in->linesize[plane];                      
                            \
-- 
2.52.0

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

Reply via email to