1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/imm5: Reference H.264/HEVC decoders directly

This is simpler and allows to fuzz them -- up until now,
the linker did not see the dependency and fuzzing them
returned AVERROR_BUG during init.
It took just a few seconds here to run into an assert
due to a return value of AVERROR(EAGAIN) in the decode
callback...

Reviewed-by: Kacper Michajlow <kasper93@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-04-21 19:13:07 +02:00
parent 0d9b0015ba
commit 0279eb9c93

View File

@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/attributes_internal.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avcodec.h" #include "avcodec.h"
@ -51,32 +52,27 @@ static const struct IMM5_unit {
static av_cold int imm5_init(AVCodecContext *avctx) static av_cold int imm5_init(AVCodecContext *avctx)
{ {
IMM5Context *ctx = avctx->priv_data; IMM5Context *ctx = avctx->priv_data;
const AVCodec *codec;
int ret; int ret;
codec = avcodec_find_decoder(AV_CODEC_ID_H264); EXTERN const FFCodec ff_h264_decoder;
if (!codec) ctx->h264_avctx = avcodec_alloc_context3(&ff_h264_decoder.p);
return AVERROR_BUG;
ctx->h264_avctx = avcodec_alloc_context3(codec);
if (!ctx->h264_avctx) if (!ctx->h264_avctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
ctx->h264_avctx->thread_count = 1; ctx->h264_avctx->thread_count = 1;
ctx->h264_avctx->flags = avctx->flags; ctx->h264_avctx->flags = avctx->flags;
ctx->h264_avctx->flags2 = avctx->flags2; ctx->h264_avctx->flags2 = avctx->flags2;
ret = avcodec_open2(ctx->h264_avctx, codec, NULL); ret = avcodec_open2(ctx->h264_avctx, NULL, NULL);
if (ret < 0) if (ret < 0)
return ret; return ret;
codec = avcodec_find_decoder(AV_CODEC_ID_HEVC); EXTERN const FFCodec ff_hevc_decoder;
if (!codec) ctx->hevc_avctx = avcodec_alloc_context3(&ff_hevc_decoder.p);
return AVERROR_BUG;
ctx->hevc_avctx = avcodec_alloc_context3(codec);
if (!ctx->hevc_avctx) if (!ctx->hevc_avctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
ctx->hevc_avctx->thread_count = 1; ctx->hevc_avctx->thread_count = 1;
ctx->hevc_avctx->flags = avctx->flags; ctx->hevc_avctx->flags = avctx->flags;
ctx->hevc_avctx->flags2 = avctx->flags2; ctx->hevc_avctx->flags2 = avctx->flags2;
ret = avcodec_open2(ctx->hevc_avctx, codec, NULL); ret = avcodec_open2(ctx->hevc_avctx, NULL, NULL);
if (ret < 0) if (ret < 0)
return ret; return ret;