1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

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>
This commit is contained in:
Andreas Rheinhardt 2021-08-23 13:54:19 +02:00
parent c1f4858242
commit e304f5f758

View File

@ -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;
}