ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | 
Thu Jul  3 22:32:15 2025 +0200| [fadadb56e665521cb6e11f8dd13a2a0a83927f5c] | 
committer: Andreas Rheinhardt

avcodec/mpegvideo_dec: Avoid implicit NULL + offset

Happens since 4fc874ef0813d39983f9b634cec42798aa94b57a
when this code is called via error resilience.
Also do the same for wmv2dec.c.
Fixes the vsynth_{1,2,3,_lena}-mpeg4-error and wmv2-drm-dec FATE-tests.

Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>

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

 libavcodec/mpegvideo_dec.c | 50 +++++++++++++++++++++++-----------------------
 libavcodec/wmv2dec.c       | 15 +++++++-------
 2 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index e9d0009f3c..4a54f6cd61 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -851,10 +851,10 @@ unhandled:
 
 /* add block[] to dest[] */
 static inline void add_dct(MpegEncContext *s,
-                           int16_t *block, int i, uint8_t *dest, int line_size)
+                           int16_t block[][64], int i, uint8_t *dest, int 
line_size)
 {
     if (s->block_last_index[i] >= 0) {
-        s->idsp.idct_add(dest, line_size, block);
+        s->idsp.idct_add(dest, line_size, block[i]);
     }
 }
 
@@ -867,12 +867,12 @@ static inline void put_dct(MpegEncContext *s,
 }
 
 static inline void add_dequant_dct(MpegEncContext *s,
-                           int16_t *block, int i, uint8_t *dest, int 
line_size, int qscale)
+                                   int16_t block[][64], int i, uint8_t *dest, 
int line_size, int qscale)
 {
     if (s->block_last_index[i] >= 0) {
-        s->dct_unquantize_inter(s, block, i, qscale);
+        s->dct_unquantize_inter(s, block[i], i, qscale);
 
-        s->idsp.idct_add(dest, line_size, block);
+        s->idsp.idct_add(dest, line_size, block[i]);
     }
 }
 
@@ -959,44 +959,44 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, 
int16_t block[12][64],
         /* add dct residue */
         if (is_mpeg12 != DEFINITELY_MPEG12_H261 && s->dct_unquantize_inter) {
             // H.263, H.263+, H.263I, FLV, RV10, RV20 and MPEG-4 with MPEG-2 
quantization
-            add_dequant_dct(s, block[0], 0, dest_y                          , 
dct_linesize, s->qscale);
-            add_dequant_dct(s, block[1], 1, dest_y              + block_size, 
dct_linesize, s->qscale);
-            add_dequant_dct(s, block[2], 2, dest_y + dct_offset             , 
dct_linesize, s->qscale);
-            add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, 
dct_linesize, s->qscale);
+            add_dequant_dct(s, block, 0, dest_y                          , 
dct_linesize, s->qscale);
+            add_dequant_dct(s, block, 1, dest_y              + block_size, 
dct_linesize, s->qscale);
+            add_dequant_dct(s, block, 2, dest_y + dct_offset             , 
dct_linesize, s->qscale);
+            add_dequant_dct(s, block, 3, dest_y + dct_offset + block_size, 
dct_linesize, s->qscale);
 
             if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
                 av_assert2(s->chroma_y_shift);
-                add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, 
s->chroma_qscale);
-                add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, 
s->chroma_qscale);
+                add_dequant_dct(s, block, 4, dest_cb, uvlinesize, 
s->chroma_qscale);
+                add_dequant_dct(s, block, 5, dest_cr, uvlinesize, 
s->chroma_qscale);
             }
         } else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || 
(s->codec_id != AV_CODEC_ID_WMV2)) {
             // H.261, MPEG-1, MPEG-2, MPEG-4 with H.263 quantization,
             // MSMP4V1-3 and WMV1.
             // Also RV30, RV40 and the VC-1 family when performing error 
resilience,
             // but all blocks are skipped in this case.
-            add_dct(s, block[0], 0, dest_y                          , 
dct_linesize);
-            add_dct(s, block[1], 1, dest_y              + block_size, 
dct_linesize);
-            add_dct(s, block[2], 2, dest_y + dct_offset             , 
dct_linesize);
-            add_dct(s, block[3], 3, dest_y + dct_offset + block_size, 
dct_linesize);
+            add_dct(s, block, 0, dest_y                          , 
dct_linesize);
+            add_dct(s, block, 1, dest_y              + block_size, 
dct_linesize);
+            add_dct(s, block, 2, dest_y + dct_offset             , 
dct_linesize);
+            add_dct(s, block, 3, dest_y + dct_offset + block_size, 
dct_linesize);
 
             if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
                 if (s->chroma_y_shift) {//Chroma420
-                    add_dct(s, block[4], 4, dest_cb, uvlinesize);
-                    add_dct(s, block[5], 5, dest_cr, uvlinesize);
+                    add_dct(s, block, 4, dest_cb, uvlinesize);
+                    add_dct(s, block, 5, dest_cr, uvlinesize);
                 } else {
                     //chroma422
                     dct_linesize = uvlinesize << s->interlaced_dct;
                     dct_offset   = s->interlaced_dct ? uvlinesize : 
uvlinesize*block_size;
 
-                    add_dct(s, block[4], 4, dest_cb, dct_linesize);
-                    add_dct(s, block[5], 5, dest_cr, dct_linesize);
-                    add_dct(s, block[6], 6, dest_cb + dct_offset, 
dct_linesize);
-                    add_dct(s, block[7], 7, dest_cr + dct_offset, 
dct_linesize);
+                    add_dct(s, block, 4, dest_cb, dct_linesize);
+                    add_dct(s, block, 5, dest_cr, dct_linesize);
+                    add_dct(s, block, 6, dest_cb + dct_offset, dct_linesize);
+                    add_dct(s, block, 7, dest_cr + dct_offset, dct_linesize);
                     if (!s->chroma_x_shift) {//Chroma444
-                        add_dct(s, block[8],   8, dest_cb + block_size, 
dct_linesize);
-                        add_dct(s, block[9],   9, dest_cr + block_size, 
dct_linesize);
-                        add_dct(s, block[10], 10, dest_cb + block_size + 
dct_offset, dct_linesize);
-                        add_dct(s, block[11], 11, dest_cr + block_size + 
dct_offset, dct_linesize);
+                        add_dct(s, block,  8, dest_cb + block_size, 
dct_linesize);
+                        add_dct(s, block,  9, dest_cr + block_size, 
dct_linesize);
+                        add_dct(s, block, 10, dest_cb + block_size + 
dct_offset, dct_linesize);
+                        add_dct(s, block, 11, dest_cr + block_size + 
dct_offset, dct_linesize);
                     }
                 }
             } //fi gray
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 082ebf7a84..512d63b23e 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -56,12 +56,13 @@ typedef struct WMV2DecContext {
     DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64];
 } WMV2DecContext;
 
-static void wmv2_add_block(WMV2DecContext *w, int16_t *block1,
+static void wmv2_add_block(WMV2DecContext *w, int16_t blocks1[][64],
                            uint8_t *dst, int stride, int n)
 {
     H263DecContext *const h = &w->ms.h;
 
     if (h->c.block_last_index[n] >= 0) {
+        int16_t *block1 = blocks1[n];
         switch (w->abt_type_table[n]) {
         case 0:
             w->common.wdsp.idct_add(dst, stride, block1);
@@ -87,16 +88,16 @@ void ff_wmv2_add_mb(MpegEncContext *s, int16_t 
block1[6][64],
 {
     WMV2DecContext *const w = (WMV2DecContext *) s;
 
-    wmv2_add_block(w, block1[0], dest_y,                       s->linesize, 0);
-    wmv2_add_block(w, block1[1], dest_y + 8,                   s->linesize, 1);
-    wmv2_add_block(w, block1[2], dest_y + 8 * s->linesize,     s->linesize, 2);
-    wmv2_add_block(w, block1[3], dest_y + 8 + 8 * s->linesize, s->linesize, 3);
+    wmv2_add_block(w, block1, dest_y,                       s->linesize, 0);
+    wmv2_add_block(w, block1, dest_y + 8,                   s->linesize, 1);
+    wmv2_add_block(w, block1, dest_y + 8 * s->linesize,     s->linesize, 2);
+    wmv2_add_block(w, block1, dest_y + 8 + 8 * s->linesize, s->linesize, 3);
 
     if (s->avctx->flags & AV_CODEC_FLAG_GRAY)
         return;
 
-    wmv2_add_block(w, block1[4], dest_cb, s->uvlinesize, 4);
-    wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5);
+    wmv2_add_block(w, block1, dest_cb, s->uvlinesize, 4);
+    wmv2_add_block(w, block1, dest_cr, s->uvlinesize, 5);
 }
 
 static int parse_mb_skip(WMV2DecContext *w)

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to