[FFmpeg-cvslog] avcodec/mpeg4videoenc: Fix data race when using AC prediction

Andreas Rheinhardt git at videolan.org
Sat Jun 21 23:21:39 EEST 2025


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sat Jun 14 03:47:00 2025 +0200| [34953e195fe108224abdfe25d147f1a7ba5477c8] | committer: Andreas Rheinhardt

avcodec/mpeg4videoenc: Fix data race when using AC prediction

The check for whether we can use the fast path to process
AC coefficients used the qscale value belonging to a different
slice; this worked in practice, because the predicted AC values
are zero in this case, so it does not matter whether we use
the fast or the slow path.

Fix this by checking for first_slice_line instead. This fixes all
the races in the encoding part of the vsynth*-mpeg4-thread tests
(and fixes them if no frame threading is in use for the decoding part).

(The left prediction check may use data from a different slice, too,
but said slice is always processed by the same thread, so that no race
can happen. Given that out-of-slice AC values are zero, it does not
matter whether we use the fast path or the slow path either.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=34953e195fe108224abdfe25d147f1a7ba5477c8
---

 libavcodec/mpeg4videoenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 1b8ccad380..a9d673707a 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -205,7 +205,7 @@ static inline int decide_ac_pred(MPVEncContext *const s, int16_t block[6][64],
             const int xy = s->c.mb_x + s->c.mb_y * s->c.mb_stride - s->c.mb_stride;
             /* top prediction */
             ac_val -= s->c.block_wrap[n] * 16;
-            if (s->c.mb_y == 0 || s->c.qscale == qscale_table[xy] || n == 2 || n == 3) {
+            if (s->c.first_slice_line || s->c.qscale == qscale_table[xy] || n == 2 || n == 3) {
                 /* same qscale */
                 for (i = 1; i < 8; i++) {
                     const int level = block[n][s->c.idsp.idct_permutation[i]];



More information about the ffmpeg-cvslog mailing list