[PATCH 01/10] fftools/ffmpeg_enc: simplify opaque_ref check
Found-while-revieweing: CID1520670 Dereference after null check Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffmpeg_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 618ba193ff5..863d1a43edd 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -476,7 +476,7 @@ void enc_stats_write(OutputStream *ost, EncStats *es, const FrameData *fd; - if ((frame && frame->opaque_ref) || (pkt && pkt->opaque_ref)) { + if (frame ? frame->opaque_ref : pkt->opaque_ref) { fd = (const FrameData*)(frame ? frame->opaque_ref->data : pkt->opaque_ref->data); tbi = fd->dec.tb; ptsi = fd->dec.pts; -- 2.43.2
Fixes: CID1520677 Uninitialized pointer read Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffmpeg_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 863d1a43edd..0b3f3f101a2 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -474,7 +474,7 @@ void enc_stats_write(OutputStream *ost, EncStats *es, AVRational tbi = (AVRational){ 0, 1}; int64_t ptsi = INT64_MAX; - const FrameData *fd; + const FrameData *fd = NULL; if (frame ? frame->opaque_ref : pkt->opaque_ref) { fd = (const FrameData*)(frame ? frame->opaque_ref->data : pkt->opaque_ref->data); -- 2.43.2
Fixes: CID1591439 Uninitialized pointer read Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffmpeg_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 0b3f3f101a2..928114c20ff 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -168,7 +168,7 @@ int enc_open(void *opaque, const AVFrame *frame) InputStream *ist = ost->ist; Encoder *e = ost->enc; AVCodecContext *enc_ctx = ost->enc_ctx; - Decoder *dec; + Decoder *dec = NULL; const AVCodec *enc = enc_ctx->codec; OutputFile *of = ost->file; FrameData *fd; -- 2.43.2
Not sure this change makes sense, the code is more robust with ret set Fixes: CID1559178 Unused value Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffmpeg_mux.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index a1583edd618..4306067eca2 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -290,7 +290,7 @@ static int mux_packet_filter(Muxer *mux, MuxThreadContext *mt, { MuxStream *ms = ms_from_ost(ost); const char *err_msg; - int ret = 0; + int ret; if (pkt && !ost->enc) { ret = of_streamcopy(&mux->of, ost, pkt); @@ -299,7 +299,6 @@ static int mux_packet_filter(Muxer *mux, MuxThreadContext *mt, else if (ret == AVERROR_EOF) { av_packet_unref(pkt); pkt = NULL; - ret = 0; *stream_eof = 1; } else if (ret < 0) goto fail; -- 2.43.2
Fixes: CID1538863 Resource leak Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffmpeg_mux_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 8797265145c..b1cb6cf7bd7 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -3025,7 +3025,7 @@ static int parse_forced_key_frames(void *log, KeyframeForceCtx *kf, if (nb_ch > INT_MAX - size || !(pts = av_realloc_f(pts, size += nb_ch - 1, sizeof(*pts)))) - return AVERROR(ENOMEM); + goto fail; if (p[8]) { ret = av_parse_time(&t, p + 8, 1); -- 2.43.2
On Sun, Apr 28, 2024 at 01:54:19AM +0200, Michael Niedermayer wrote:
Fixes: CID1538863 Resource leak
Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffmpeg_mux_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
will apply [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Homeopathy is like voting while filling the ballot out with transparent ink. Sometimes the outcome one wanted occurs. Rarely its worse than filling out a ballot properly.
Fixes: CID1539099 Resource leak Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffmpeg.h | 9 +++++++-- fftools/ffmpeg_mux_init.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 885a7c0c102..7fd6c57d50f 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -868,7 +868,7 @@ void update_benchmark(const char *fmt, ...); namestr, st->index, o->optname.opt_canon->name, spec[0] ? ":" : "", spec, so->u.type);\ } -#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ +#define MATCH_PER_STREAM_OPT_CLEAN(name, type, outvar, fmtctx, st, clean)\ {\ int _ret, _matches = 0, _match_idx;\ for (int _i = 0; _i < o->name.nb_opt; _i++) {\ @@ -878,12 +878,17 @@ void update_benchmark(const char *fmt, ...); _match_idx = _i;\ _matches++;\ } else if (_ret < 0)\ - return _ret;\ + clean;\ }\ if (_matches > 1 && o->name.opt_canon)\ WARN_MULTIPLE_OPT_USAGE(name, type, _match_idx, st);\ } +#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ +{\ + MATCH_PER_STREAM_OPT_CLEAN(name, type, outvar, fmtctx, st, return _ret)\ +} + const char *opt_match_per_type_str(const SpecifierOptList *sol, char mediatype); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index b1cb6cf7bd7..1262630b24e 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -2933,7 +2933,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) nb_streams[ost->type + 1]++; - MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st); + MATCH_PER_STREAM_OPT_CLEAN(disposition, str, dispositions[i], ctx, ost->st, goto finish); have_manual |= !!dispositions[i]; -- 2.43.2
issue found while reviewing CID1452612 Free of array-typed value Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/cmdutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index a8f5c6d89b4..d28f5f3a8bd 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -578,7 +578,7 @@ static const AVOption *opt_find(void *obj, const char *name, const char *unit, return o; } -#define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0 +#define FLAGS ((o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0) int opt_default(void *optctx, const char *opt, const char *arg) { const AVOption *o; -- 2.43.2
On Sun, Apr 28, 2024 at 01:54:21AM +0200, Michael Niedermayer wrote:
issue found while reviewing CID1452612 Free of array-typed value
Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/cmdutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
will apply [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement. For even the very wise cannot see all ends. -- Gandalf
Fixes: CID1592383 Unused value Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffmpeg_sched.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index e58b00ea97b..cff824340b7 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -2174,7 +2174,7 @@ finish: int sch_dec_send(Scheduler *sch, unsigned dec_idx, AVFrame *frame) { SchDec *dec; - int ret = 0; + int ret; unsigned nb_done = 0; av_assert0(dec_idx < sch->nb_dec); @@ -2201,7 +2201,6 @@ int sch_dec_send(Scheduler *sch, unsigned dec_idx, AVFrame *frame) av_frame_unref(to_send); if (ret == AVERROR_EOF) { nb_done++; - ret = 0; continue; } return ret; -- 2.43.2
This probably makes no difference but its more correct Fixes: CID1503080 Unchecked return value Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffplay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffplay.c b/fftools/ffplay.c index d4300d5d46e..63a9806fb80 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -2392,11 +2392,11 @@ static int audio_decode_frame(VideoState *is) af->frame->sample_rate != is->audio_src.freq || (wanted_nb_samples != af->frame->nb_samples && !is->swr_ctx)) { swr_free(&is->swr_ctx); - swr_alloc_set_opts2(&is->swr_ctx, + int ret = swr_alloc_set_opts2(&is->swr_ctx, &is->audio_tgt.ch_layout, is->audio_tgt.fmt, is->audio_tgt.freq, &af->frame->ch_layout, af->frame->format, af->frame->sample_rate, 0, NULL); - if (!is->swr_ctx || swr_init(is->swr_ctx) < 0) { + if (ret < 0 || swr_init(is->swr_ctx) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n", af->frame->sample_rate, av_get_sample_fmt_name(af->frame->format), af->frame->ch_layout.nb_channels, -- 2.43.2
On Sun, Apr 28, 2024 at 01:54:23AM +0200, Michael Niedermayer wrote:
This probably makes no difference but its more correct
Fixes: CID1503080 Unchecked return value
Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffplay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
will apply [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope
Fixes: CID1550133 Unchecked return value Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffplay.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 63a9806fb80..cc00e209d52 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3839,8 +3839,13 @@ int main(int argc, char **argv) if (vk_renderer) { AVDictionary *dict = NULL; - if (vulkan_params) - av_dict_parse_string(&dict, vulkan_params, "=", ":", 0); + if (vulkan_params) { + int ret = av_dict_parse_string(&dict, vulkan_params, "=", ":", 0); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Failed to parse, %s\n", vulkan_params); + do_exit(NULL); + } + } ret = vk_renderer_create(vk_renderer, window, dict); av_dict_free(&dict); if (ret < 0) { -- 2.43.2
On Sun, Apr 28, 2024 at 01:54:15AM +0200, Michael Niedermayer wrote:
Found-while-revieweing: CID1520670 Dereference after null check
Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- fftools/ffmpeg_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
will apply the remaining patches of this set [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Take away the freedom of one citizen and you will be jailed, take away the freedom of all citizens and you will be congratulated by your peers in Parliament.
participants (1)
-
Michael Niedermayer