diff mbox series

[FFmpeg-devel] avcodec/mimic: Fix undefined pointer arithmetic

Message ID DB6PR0101MB2214758B114E1AF1278B94258F679@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit c1b966a189f3ffef8bd48d744e644f573a218608
Headers show
Series [FFmpeg-devel] avcodec/mimic: Fix undefined pointer arithmetic | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 12, 2022, 12:40 p.m. UTC
NULL + anything is UB.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mimic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Aug. 12, 2022, 5:32 p.m. UTC | #1
On Fri, Aug 12, 2022 at 02:40:43PM +0200, Andreas Rheinhardt wrote:
> NULL + anything is UB.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/mimic.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

if its NULL, LGTM

thx

[...]
Andreas Rheinhardt Aug. 12, 2022, 5:36 p.m. UTC | #2
Michael Niedermayer:
> On Fri, Aug 12, 2022 at 02:40:43PM +0200, Andreas Rheinhardt wrote:
>> NULL + anything is UB.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/mimic.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> if its NULL, LGTM
> 

It is (at least for the first keyframe). So I will therefore apply this.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c
index ce5c2afd19..bcf10b7ae1 100644
--- a/libavcodec/mimic.c
+++ b/libavcodec/mimic.c
@@ -268,8 +268,9 @@  static int decode(MimicContext *ctx, int quality, int num_coeffs,
         const int qscale    = av_clip(10000 - quality, is_chroma ? 1000 : 2000,
                                       10000) << 2;
         const int stride    = ctx->frames[ctx->cur_index ].f->linesize[plane];
-        const uint8_t *src  = ctx->frames[ctx->prev_index].f->data[plane];
         uint8_t       *dst  = ctx->frames[ctx->cur_index ].f->data[plane];
+        /* src is unused for I frames; set to avoid UB pointer arithmetic. */
+        const uint8_t *src  = is_iframe ? dst : ctx->frames[ctx->prev_index].f->data[plane];
 
         for (y = 0; y < ctx->num_vblocks[plane]; y++) {
             for (x = 0; x < ctx->num_hblocks[plane]; x++) {