[FFmpeg-devel] [PATCH] avcodec/pngdec: Store metadata directly into AVFrame
Michael Niedermayer
michael at niedermayer.cc
Thu Feb 2 23:27:30 EET 2017
Fixes memleak
Fixes: 500/clusterfuzz-testcase-6315221727576064
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
libavcodec/pngdec.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 50a0a296b3..42753b3052 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1087,7 +1087,7 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s,
static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
AVFrame *p, AVPacket *avpkt)
{
- AVDictionary *metadata = NULL;
+ AVDictionary **metadatap = NULL;
uint32_t tag, length;
int decode_next_dat = 0;
int ret;
@@ -1098,7 +1098,6 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
if (avctx->codec_id == AV_CODEC_ID_PNG &&
avctx->skip_frame == AVDISCARD_ALL) {
- av_frame_set_metadata(p, metadata);
return 0;
}
@@ -1144,6 +1143,7 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
}
}
+ metadatap = avpriv_frame_get_metadatap(p);
switch (tag) {
case MKTAG('I', 'H', 'D', 'R'):
if ((ret = decode_ihdr_chunk(avctx, s, length)) < 0)
@@ -1185,12 +1185,12 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
goto skip_tag;
break;
case MKTAG('t', 'E', 'X', 't'):
- if (decode_text_chunk(s, length, 0, &metadata) < 0)
+ if (decode_text_chunk(s, length, 0, metadatap) < 0)
av_log(avctx, AV_LOG_WARNING, "Broken tEXt chunk\n");
bytestream2_skip(&s->gb, length + 4);
break;
case MKTAG('z', 'T', 'X', 't'):
- if (decode_text_chunk(s, length, 1, &metadata) < 0)
+ if (decode_text_chunk(s, length, 1, metadatap) < 0)
av_log(avctx, AV_LOG_WARNING, "Broken zTXt chunk\n");
bytestream2_skip(&s->gb, length + 4);
break;
@@ -1227,9 +1227,9 @@ skip_tag:
}
}
exit_loop:
+
if (avctx->codec_id == AV_CODEC_ID_PNG &&
avctx->skip_frame == AVDISCARD_ALL) {
- av_frame_set_metadata(p, metadata);
return 0;
}
@@ -1277,12 +1277,9 @@ exit_loop:
ff_thread_report_progress(&s->picture, INT_MAX, 0);
ff_thread_report_progress(&s->previous_picture, INT_MAX, 0);
- av_frame_set_metadata(p, metadata);
- metadata = NULL;
return 0;
fail:
- av_dict_free(&metadata);
ff_thread_report_progress(&s->picture, INT_MAX, 0);
ff_thread_report_progress(&s->previous_picture, INT_MAX, 0);
return ret;
--
2.11.0
More information about the ffmpeg-devel
mailing list