PR #22740 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22740
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22740.patch

To reproduce:
```
> make libswscale/tests/swscale; and libswscale/tests/swscale -flags unstable 
> -src argb -dst rgb24
```


>From baaf56934c6c237993dfa41e1650b9dbc0a56660 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Tue, 7 Apr 2026 16:29:13 +0200
Subject: [PATCH 1/2] swscale/ops_optimizer: properly swizzle comps_src when
 splitting

Fixes a pre-existing latent bug in the subpass splitting, that was
made worse / exposed by 048ca3b367b.

Fixes: cba54e9e3b2810243cc281244305848abd99f7dd
Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/ops_optimizer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libswscale/ops_optimizer.c b/libswscale/ops_optimizer.c
index f44a44e1b7..7df5549fe8 100644
--- a/libswscale/ops_optimizer.c
+++ b/libswscale/ops_optimizer.c
@@ -967,14 +967,15 @@ int ff_sws_op_list_subpass(SwsOpList *ops1, SwsOpList 
**out_rest)
 
     /* Determine metadata for the intermediate format */
     const SwsPixelType type = op->type;
-    ops2->comps_src = prev->comps;
     ops2->src.format = get_planar_fmt(type, nb_planes);
     ops2->src.desc = av_pix_fmt_desc_get(ops2->src.format);
     get_input_size(ops1, &ops2->src);
     ops1->dst = ops2->src;
 
-    for (int i = 0; i < nb_planes; i++)
+    for (int i = 0; i < nb_planes; i++) {
         ops1->plane_dst[i] = ops2->plane_src[i] = i;
+        ops2->comps_src.flags[i] = prev->comps.flags[swiz_wr.in[i]];
+    }
 
     ff_sws_op_list_remove_at(ops1, idx, ops1->num_ops - idx);
     ff_sws_op_list_remove_at(ops2, 0, idx);
-- 
2.52.0


>From 2cebabdcc63d73f111ee81f23d2445fd988e9e32 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Tue, 7 Apr 2026 16:31:43 +0200
Subject: [PATCH 2/2] swscale/ops: add assertion that comps_src is sane

This assertion guards against bugs like that fixed in the previous
commit.

Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/ops.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libswscale/ops.c b/libswscale/ops.c
index 5d7e70c133..035e0e589a 100644
--- a/libswscale/ops.c
+++ b/libswscale/ops.c
@@ -336,6 +336,7 @@ void ff_sws_op_list_update_comps(SwsOpList *ops)
              * other components are explicitly stripped */
             for (int i = 0; i < op->rw.elems; i++) {
                 const int idx = op->rw.packed ? i : ops->plane_src[i];
+                av_assert0(!(ops->comps_src.flags[idx] & SWS_COMP_GARBAGE));
                 op->comps.flags[i] = ops->comps_src.flags[idx];
                 op->comps.min[i]   = ops->comps_src.min[idx];
                 op->comps.max[i]   = ops->comps_src.max[idx];
-- 
2.52.0

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

Reply via email to