diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-08-23 14:37:04 +0300 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-08-28 16:25:18 +0300 |
commit | c1f48582428f7d5e7d93d2f0af6d4612559f74ca (patch) | |
tree | 4855edef6fd8239024576c94b48b2fdf90d500fc /libavformat/flac_picture.c | |
parent | b10a8a30dbf605fb0761c9ee64cfbe8cb87ba710 (diff) |
avformat/flac_picture: Try to reuse buffer for attached picture
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/flac_picture.c')
-rw-r--r-- | libavformat/flac_picture.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c index 96e14f76c9..e7660a7db1 100644 --- a/libavformat/flac_picture.c +++ b/libavformat/flac_picture.c @@ -29,12 +29,13 @@ #define MAX_TRUNC_PICTURE_SIZE (500 * 1024 * 1024) -int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, int truncate_workaround) +int ff_flac_parse_picture(AVFormatContext *s, uint8_t **bufp, int buf_size, + int truncate_workaround) { const CodecMime *mime = ff_id3v2_mime_tags; enum AVCodecID id = AV_CODEC_ID_NONE; AVBufferRef *data = NULL; - uint8_t mimetype[64], *desc = NULL; + uint8_t mimetype[64], *desc = NULL, *buf = *bufp; GetByteContext g; AVStream *st; int width, height, ret = 0; @@ -142,6 +143,15 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, int tr goto fail; } } + if (trunclen == 0 && len >= buf_size - (buf_size >> 4)) { + data = av_buffer_create(buf, buf_size + AV_INPUT_BUFFER_PADDING_SIZE, + av_buffer_default_free, NULL, 0); + if (!data) + RETURN_ERROR(AVERROR(ENOMEM)); + *bufp = NULL; + data->data += bytestream2_tell(&g); + data->size = len + AV_INPUT_BUFFER_PADDING_SIZE; + } else { if (!(data = av_buffer_alloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) { RETURN_ERROR(AVERROR(ENOMEM)); } @@ -155,6 +165,7 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, int tr if (avio_read(s->pb, data->data + len - trunclen, trunclen) < trunclen) RETURN_ERROR(AVERROR_INVALIDDATA); } + } memset(data->data + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); if (AV_RB64(data->data) == PNGSIG) |