diff --git a/libavcodec/bitstream_filter.c b/libavcodec/bitstream_filter.c index 3275326db4..a4e437df5f 100644 --- a/libavcodec/bitstream_filter.c +++ b/libavcodec/bitstream_filter.c @@ -49,9 +49,17 @@ AVBitStreamFilterContext *av_bitstream_filter_init(const char *name) if (!strcmp(name, bsf->name)) { AVBitStreamFilterContext *bsfc = av_mallocz(sizeof(AVBitStreamFilterContext)); + if (!bsfc) + return NULL; bsfc->filter = bsf; - bsfc->priv_data = - bsf->priv_data_size ? av_mallocz(bsf->priv_data_size) : NULL; + bsfc->priv_data = NULL; + if (bsf->priv_data_size) { + bsfc->priv_data = av_mallocz(bsf->priv_data_size); + if (!bsfc->priv_data) { + av_freep(&bsfc); + return NULL; + } + } return bsfc; } } diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c index 2dcbf8fdad..568f920979 100644 --- a/libavcodec/dump_extradata_bsf.c +++ b/libavcodec/dump_extradata_bsf.c @@ -37,6 +37,8 @@ static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, int size= buf_size + avctx->extradata_size; *poutbuf_size= size; *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!*poutbuf) + return AVERROR(ENOMEM); memcpy(*poutbuf, avctx->extradata, avctx->extradata_size); memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); diff --git a/libavcodec/imx_dump_header_bsf.c b/libavcodec/imx_dump_header_bsf.c index be43fbc159..d53f338a4f 100644 --- a/libavcodec/imx_dump_header_bsf.c +++ b/libavcodec/imx_dump_header_bsf.c @@ -43,6 +43,8 @@ static int imx_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx } *poutbuf = av_malloc(buf_size + 20 + FF_INPUT_BUFFER_PADDING_SIZE); + if (!*poutbuf) + return AVERROR(ENOMEM); poutbufp = *poutbuf; bytestream_put_buffer(&poutbufp, imx_header, 16); bytestream_put_byte(&poutbufp, 0x83); /* KLV BER long form */ diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c index 3947c821a8..87829fae8f 100644 --- a/libavcodec/mjpega_dump_header_bsf.c +++ b/libavcodec/mjpega_dump_header_bsf.c @@ -45,6 +45,8 @@ static int mjpega_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *av *poutbuf_size = 0; *poutbuf = av_malloc(buf_size + 44 + FF_INPUT_BUFFER_PADDING_SIZE); + if (!*poutbuf) + return AVERROR(ENOMEM); poutbufp = *poutbuf; bytestream_put_byte(&poutbufp, 0xff); bytestream_put_byte(&poutbufp, SOI); diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c index 123c7a547d..4820b26388 100644 --- a/libavcodec/movsub_bsf.c +++ b/libavcodec/movsub_bsf.c @@ -29,6 +29,8 @@ static int text2movsub(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, co if (buf_size > 0xffff) return 0; *poutbuf_size = buf_size + 2; *poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!*poutbuf) + return AVERROR(ENOMEM); AV_WB16(*poutbuf, buf_size); memcpy(*poutbuf + 2, buf, buf_size); return 1; @@ -45,6 +47,8 @@ static int mov2textsub(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, co if (buf_size < 2) return 0; *poutbuf_size = FFMIN(buf_size - 2, AV_RB16(buf)); *poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!*poutbuf) + return AVERROR(ENOMEM); memcpy(*poutbuf, buf + 2, *poutbuf_size); return 1; } diff --git a/libavcodec/parser.c b/libavcodec/parser.c index 8a3be295aa..2c03b7e5c5 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -200,6 +200,8 @@ int av_parser_change(AVCodecParserContext *s, AVCodecContext *avctx, *poutbuf_size = size; *poutbuf = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!*poutbuf) + return AVERROR(ENOMEM); memcpy(*poutbuf, avctx->extradata, avctx->extradata_size); memcpy(*poutbuf + avctx->extradata_size, buf,