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

put_vc1_mspel_mc_v_lasx() and put_vc1_mspel_mc_h_lasx() keep the rounding
constant in a function-local "static int add_value[3]" and rewrite it on
every call, which makes both functions non-reentrant.

The rnd bit is read from the bitstream, so with two callers active at once
the second one can store its own constant between the first one's store and
the __lasx_xvreplgr2vr_h() load. The frame that loses the race is
interpolated with the other one's rounding term and comes out bit-inexact,
which shows up as a handful of frames per run and moves around from run to
run. It is reachable today by decoding two vc1/wmv3 streams in two threads
of one process with separate contexts, and it makes frame-threaded
decoding non-deterministic.

Use a plain automatic variable, like every other mspel implementation does.



>From 0cd4f7b70ce7976319dba164ba8e822a5f2d4612 Mon Sep 17 00:00:00 2001
From: jinbo <[email protected]>
Date: Wed, 25 Nov 2026 09:29:19 +0800
Subject: [PATCH] avcodec/loongarch/vc1dsp: keep the mspel rounding term in
 local storage

put_vc1_mspel_mc_v_lasx() and put_vc1_mspel_mc_h_lasx() keep the rounding
constant in a function-local "static int add_value[3]" and rewrite it on
every call, which makes both functions non-reentrant.

The rnd bit is read from the bitstream, so with two callers active at once
the second one can store its own constant between the first one's store and
the __lasx_xvreplgr2vr_h() load. The frame that loses the race is
interpolated with the other one's rounding term and comes out bit-inexact,
which shows up as a handful of frames per run and moves around from run to
run. It is reachable today by decoding two vc1/wmv3 streams in two threads
of one process with separate contexts, and it makes frame-threaded
decoding non-deterministic.

Use a plain automatic variable, like every other mspel implementation does.
---
 libavcodec/loongarch/vc1dsp_lasx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/loongarch/vc1dsp_lasx.c 
b/libavcodec/loongarch/vc1dsp_lasx.c
index 848fe4afb34..0581ad6b3fd 100644
--- a/libavcodec/loongarch/vc1dsp_lasx.c
+++ b/libavcodec/loongarch/vc1dsp_lasx.c
@@ -745,7 +745,7 @@ static void put_vc1_mspel_mc_v_lasx(uint8_t *dst, const 
uint8_t *src,
                                             {0x0403, 0x3512}};
     const uint16_t *para_v = para_value[vmode - 1];
     static const int shift_value[] = {0, 6, 4, 6};
-    static int add_value[3];
+    int add_value[3];
     ptrdiff_t stride_2x = stride << 1;
     int i = 0;
     add_value[2] = add_value[0] = 31 + rnd, add_value[1] = 7 + rnd;
@@ -821,7 +821,7 @@ static void put_vc1_mspel_mc_h_lasx(uint8_t *dst, const 
uint8_t *src,
                                             {0x0403, 0x3512}};
     const uint16_t *para_v = para_value[hmode - 1];
     static const int shift_value[] = {0, 6, 4, 6};
-    static int add_value[3];
+    int add_value[3];
     uint8_t *_src = (uint8_t*)src - 1;
     add_value[2] = add_value[0] = 32 - rnd, add_value[1] = 8 - rnd;
 
-- 
2.54.1

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

Reply via email to