Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/mpegvideo_dec: Avoid implicit NULL + offset
Date: Thu, 3 Jul 2025 22:52:04 +0200
Message-ID: <AS8P250MB07444E4FC1AF2006A4F604F98F43A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)

[-- Attachment #1: Type: text/plain, Size: 27 bytes --]

Patch attached.

- Andreas

[-- Attachment #2: 0001-avcodec-mpegvideo_dec-Avoid-implicit-NULL-offset.patch --]
[-- Type: text/x-patch, Size: 8411 bytes --]

From 1f85427ebe8ac63ba0d89c49bc0df917106753cb Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Thu, 3 Jul 2025 22:32:15 +0200
Subject: [PATCH] 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.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 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)
-- 
2.45.2


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

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

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

                 reply	other threads:[~2025-07-03 20:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AS8P250MB07444E4FC1AF2006A4F604F98F43A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git