Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-08-23 14:54:19 +0300
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-08-28 16:25:18 +0300
commite304f5f7583de6fff0b36e043feacb6e02261a96 (patch)
tree8c205d660eb70fe9aa0238611ea3658dd8beae7f /libavformat/flac_picture.c
parentc1f48582428f7d5e7d93d2f0af6d4612559f74ca (diff)
avformat/flac_picture: Simplify parsing title
Don't allocate the buffer for the title ourselves, leave it to av_dict_set(). This simplifies freeing. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/flac_picture.c')
-rw-r--r--libavformat/flac_picture.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
index e7660a7db1..3b69654ff6 100644
--- a/libavformat/flac_picture.c
+++ b/libavformat/flac_picture.c
@@ -35,7 +35,8 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t **bufp, int buf_size,
const CodecMime *mime = ff_id3v2_mime_tags;
enum AVCodecID id = AV_CODEC_ID_NONE;
AVBufferRef *data = NULL;
- uint8_t mimetype[64], *desc = NULL, *buf = *bufp;
+ uint8_t mimetype[64], *buf = *bufp;
+ const uint8_t *desc = NULL;
GetByteContext g;
AVStream *st;
int width, height, ret = 0;
@@ -103,16 +104,13 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t **bufp, int buf_size,
return 0;
}
if (len > 0) {
- if (!(desc = av_malloc(len + 1))) {
- return AVERROR(ENOMEM);
- }
-
- bytestream2_get_bufferu(&g, desc, len);
- desc[len] = 0;
+ desc = g.buffer;
+ bytestream2_skipu(&g, len);
}
/* picture metadata */
width = bytestream2_get_be32u(&g);
+ ((uint8_t*)g.buffer)[-4] = '\0'; // NUL-terminate desc.
height = bytestream2_get_be32u(&g);
bytestream2_skipu(&g, 8);
@@ -124,8 +122,8 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t **bufp, int buf_size,
if (len > MAX_TRUNC_PICTURE_SIZE || len >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
av_log(s, AV_LOG_ERROR, "Attached picture metadata block too big %u\n", len);
if (s->error_recognition & AV_EF_EXPLODE)
- ret = AVERROR_INVALIDDATA;
- goto fail;
+ return AVERROR_INVALIDDATA;
+ return 0;
}
// Workaround bug for flac muxers that writs truncated metadata picture block size if
@@ -139,21 +137,21 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t **bufp, int buf_size,
} else {
av_log(s, AV_LOG_ERROR, "Attached picture metadata block too short\n");
if (s->error_recognition & AV_EF_EXPLODE)
- ret = AVERROR_INVALIDDATA;
- goto fail;
+ return AVERROR_INVALIDDATA;
+ return 0;
}
}
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));
+ return 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));
+ return AVERROR(ENOMEM);
}
if (trunclen == 0) {
@@ -181,13 +179,12 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t **bufp, int buf_size,
st->codecpar->height = height;
av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0);
if (desc)
- av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL);
+ av_dict_set(&st->metadata, "title", desc, 0);
return 0;
fail:
av_buffer_unref(&data);
- av_freep(&desc);
return ret;
}