* [FFmpeg-devel] [PATCH] avcodec/mp_cmp: reject invalid comparison function values
@ 2023-04-13 13:23 James Almer
2023-04-14 12:16 ` James Almer
0 siblings, 1 reply; 2+ messages in thread
From: James Almer @ 2023-04-13 13:23 UTC (permalink / raw)
To: ffmpeg-devel
Fixes ticket #10318.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/dvenc.c | 4 +++-
libavcodec/me_cmp.c | 9 +++++++--
libavcodec/me_cmp.h | 2 +-
libavcodec/motion_est.c | 11 +++++++----
libavcodec/mpegvideo_enc.c | 6 ++++--
libavcodec/snowenc.c | 6 ++++--
6 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 11dd5763af..cd442b524d 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -104,7 +104,9 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
ff_fdctdsp_init(&fdsp, avctx);
ff_me_cmp_init(&mecc, avctx);
ff_pixblockdsp_init(&pdsp, avctx);
- ff_set_cmp(&mecc, mecc.ildct_cmp, avctx->ildct_cmp);
+ ret = ff_set_cmp(&mecc, mecc.ildct_cmp, avctx->ildct_cmp);
+ if (ret < 0)
+ return AVERROR(EINVAL);
s->get_pixels = pdsp.get_pixels;
s->ildct_cmp = mecc.ildct_cmp[5];
diff --git a/libavcodec/me_cmp.c b/libavcodec/me_cmp.c
index e2f9f84b05..cd05e63ffd 100644
--- a/libavcodec/me_cmp.c
+++ b/libavcodec/me_cmp.c
@@ -473,8 +473,9 @@ static int zero_cmp(MpegEncContext *s, const uint8_t *a, const uint8_t *b,
return 0;
}
-void ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
+int ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
{
+ int ret = 0;
int i;
memset(cmp, 0, sizeof(void *) * 6);
@@ -533,9 +534,13 @@ void ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
#endif
default:
av_log(NULL, AV_LOG_ERROR,
- "internal error in cmp function selection\n");
+ "invalid cmp function selection\n");
+ ret = -1;
+ break;
}
}
+
+ return ret;
}
#define BUTTERFLY2(o1, o2, i1, i2) \
diff --git a/libavcodec/me_cmp.h b/libavcodec/me_cmp.h
index 90ea76c891..aefd32a7dc 100644
--- a/libavcodec/me_cmp.h
+++ b/libavcodec/me_cmp.h
@@ -89,7 +89,7 @@ void ff_me_cmp_init_ppc(MECmpContext *c, AVCodecContext *avctx);
void ff_me_cmp_init_x86(MECmpContext *c, AVCodecContext *avctx);
void ff_me_cmp_init_mips(MECmpContext *c, AVCodecContext *avctx);
-void ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type);
+int ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type);
void ff_dsputil_init_dwt(MECmpContext *c);
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index d17ffe42b4..df9d1befa8 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -309,6 +309,7 @@ int ff_init_me(MpegEncContext *s){
MotionEstContext * const c= &s->me;
int cache_size= FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT);
int dia_size= FFMAX(FFABS(s->avctx->dia_size)&255, FFABS(s->avctx->pre_dia_size)&255);
+ int ret;
if(FFMIN(s->avctx->dia_size, s->avctx->pre_dia_size) < -FFMIN(ME_MAP_SIZE, MAX_SAB_SIZE)){
av_log(s->avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n");
@@ -324,10 +325,12 @@ int ff_init_me(MpegEncContext *s){
av_log(s->avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n");
}
- ff_set_cmp(&s->mecc, s->mecc.me_pre_cmp, c->avctx->me_pre_cmp);
- ff_set_cmp(&s->mecc, s->mecc.me_cmp, c->avctx->me_cmp);
- ff_set_cmp(&s->mecc, s->mecc.me_sub_cmp, c->avctx->me_sub_cmp);
- ff_set_cmp(&s->mecc, s->mecc.mb_cmp, c->avctx->mb_cmp);
+ ret = ff_set_cmp(&s->mecc, s->mecc.me_pre_cmp, c->avctx->me_pre_cmp);
+ ret |= ff_set_cmp(&s->mecc, s->mecc.me_cmp, c->avctx->me_cmp);
+ ret |= ff_set_cmp(&s->mecc, s->mecc.me_sub_cmp, c->avctx->me_sub_cmp);
+ ret |= ff_set_cmp(&s->mecc, s->mecc.mb_cmp, c->avctx->mb_cmp);
+ if (ret < 0)
+ return ret;
c->flags = get_flags(c, 0, c->avctx->me_cmp &FF_CMP_CHROMA);
c->sub_flags= get_flags(c, 0, c->avctx->me_sub_cmp&FF_CMP_CHROMA);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 7d3c8875f2..bcd2f9ef1d 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -902,8 +902,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->quant_precision = 5;
- ff_set_cmp(&s->mecc, s->mecc.ildct_cmp, avctx->ildct_cmp);
- ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, s->frame_skip_cmp);
+ ret = ff_set_cmp(&s->mecc, s->mecc.ildct_cmp, avctx->ildct_cmp);
+ ret |= ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, s->frame_skip_cmp);
+ if (ret < 0)
+ return AVERROR(EINVAL);
if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) {
ff_h263_encode_init(s);
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 4cf7ff1145..31a48972a5 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -130,8 +130,10 @@ static av_cold int encode_init(AVCodecContext *avctx)
if (ret)
return ret;
- ff_set_cmp(&s->mecc, s->mecc.me_cmp, s->avctx->me_cmp);
- ff_set_cmp(&s->mecc, s->mecc.me_sub_cmp, s->avctx->me_sub_cmp);
+ ret = ff_set_cmp(&s->mecc, s->mecc.me_cmp, s->avctx->me_cmp);
+ ret |= ff_set_cmp(&s->mecc, s->mecc.me_sub_cmp, s->avctx->me_sub_cmp);
+ if (ret < 0)
+ return AVERROR(EINVAL);
s->input_picture = av_frame_alloc();
if (!s->input_picture)
--
2.40.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/mp_cmp: reject invalid comparison function values
2023-04-13 13:23 [FFmpeg-devel] [PATCH] avcodec/mp_cmp: reject invalid comparison function values James Almer
@ 2023-04-14 12:16 ` James Almer
0 siblings, 0 replies; 2+ messages in thread
From: James Almer @ 2023-04-14 12:16 UTC (permalink / raw)
To: ffmpeg-devel
On 4/13/2023 10:23 AM, James Almer wrote:
> Fixes ticket #10318.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/dvenc.c | 4 +++-
> libavcodec/me_cmp.c | 9 +++++++--
> libavcodec/me_cmp.h | 2 +-
> libavcodec/motion_est.c | 11 +++++++----
> libavcodec/mpegvideo_enc.c | 6 ++++--
> libavcodec/snowenc.c | 6 ++++--
> 6 files changed, 26 insertions(+), 12 deletions(-)
Will apply.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-14 12:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 13:23 [FFmpeg-devel] [PATCH] avcodec/mp_cmp: reject invalid comparison function values James Almer
2023-04-14 12:16 ` James Almer
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