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

The size of the sum buffer was computed with sizeof(*s->sum), which is the size 
of a pointer, not of an element.
This made it eight times larger than what the fast tmix path indexes, which 
uses a row stride of two times the line size. Instead, it should allocate only 
the size that is used.

The output is byte-identical: 52618 framemd5 outputs per compiler (149 pixel 
formats, 1x1 to 1920x1080, tmix fast and non-fast path, mix, runtime option 
changes) match before and after with clang and GCC 16.

| tmix=frames=3 | RSS MiB, clang | RSS MiB, GCC | CPU s, clang | CPU s, GCC |
|---|---|---|---|---|
| yuv420p 1280x720, 8 threads | 63.6 -> 46.5 | 63.1 -> 45.9 | 2.40 -> 2.38 | 
2.92 -> 2.81 |
| yuv420p 1920x1080, 8 threads | 99.9 -> 58.4 | 96.6 -> 55.1 | 3.32 -> 3.32 | 
3.97 -> 3.90 |
| yuv420p 3840x2160, 8 threads | 367.9 -> 201.9 | 355.8 -> 201.6 | 3.46 -> 3.44 
| 4.27 -> 4.35 |
| yuv420p 1920x1080, 1 thread | 96.8 -> 55.3 | 96.5 -> 54.9 | 2.50 -> 2.50 | 
2.91 -> 2.91 |
| yuv420p10le 1920x1080, 8 threads | 164.1 -> 87.1 | 169.9 -> 86.8 | 2.59 -> 
2.57 | 2.94 -> 2.95 |
| gbrpf32le 1920x1080, 8 threads | 601.5 -> 269.3 | 601.2 -> 269.0 | 3.08 -> 
3.05 | 3.35 -> 3.33 |
| yuv420p 1920x1080, 8 threads, unequal weights (non-fast path) | 96.9 -> 55.4 
| 96.6 -> 55.1 | 2.77 -> 2.81 | 2.51 -> 2.51 |

Noticed during a review sweep of ffmpeg using an LLM.

Signed-off-by: romainhedouin <[email protected]>

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From 4da0afb4b9caded6affb8cbfa39b0207d2399121 Mon Sep 17 00:00:00 2001
From: romainhedouin <[email protected]>
Date: Sun, 1 Nov 2026 22:25:50 +0100
Subject: [PATCH] avfilter/vf_mix: fix the size of the sum buffer

The size of the sum buffer was computed with sizeof(*s->sum), which is
the size of a pointer, not of an element. This made it eight times
larger than what the fast tmix path indexes, which uses a row stride of
two times the line size. Allocate the size that is used. The output is
unchanged.

Noticed during a review sweep of ffmpeg using an LLM.

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

diff --git a/libavfilter/vf_mix.c b/libavfilter/vf_mix.c
index 3143f6e9c84..c46fdb6af6d 100644
--- a/libavfilter/vf_mix.c
+++ b/libavfilter/vf_mix.c
@@ -361,7 +361,7 @@ static int config_output(AVFilterLink *outlink)
 
     if (s->tmix) {
         for (int p = 0; p < s->nb_planes; p++) {
-            s->sum[p] = av_calloc(s->linesizes[p], s->height[p] * 
sizeof(*s->sum) * 2);
+            s->sum[p] = av_calloc(s->height[p], 2 * (size_t)s->linesizes[p]);
             if (!s->sum[p])
                 return AVERROR(ENOMEM);
         }
-- 
2.54.0

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

Reply via email to