diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-01-14 14:11:22 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-01-19 11:52:15 +0100 |
commit | a04c91739974754899faf6e3495f1bcfe8d8cee0 (patch) | |
tree | f283f969d38ebe5477a50307a9f04dd82388ad14 /libavformat/matroskaenc.c | |
parent | e8065c7defddb140aa713c370536b1f59371fe05 (diff) | |
download | ffmpeg-a04c91739974754899faf6e3495f1bcfe8d8cee0.tar.gz |
avformat/matroskaenc: Don't waste bytes on ChapterAtoms length fields
Also check the (user-provided) metadata tags for being too long.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/matroskaenc.c')
-rw-r--r-- | libavformat/matroskaenc.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 65d7846e0b..e44a775bcc 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2012,12 +2012,13 @@ static int mkv_write_chapters(AVFormatContext *s) create_new_ids = mkv_new_chapter_ids_needed(s); for (unsigned i = 0; i < s->nb_chapters; i++) { - ebml_master chapteratom, chapterdisplay; const AVChapter *c = s->chapters[i]; int64_t chapterstart = av_rescale_q(c->start, c->time_base, scale); int64_t chapterend = av_rescale_q(c->end, c->time_base, scale); const AVDictionaryEntry *t; uint64_t uid = create_new_ids ? i + 1ULL : c->id; + EBML_WRITER(7); + if (chapterstart < 0 || chapterstart > chapterend || chapterend < 0) { av_log(s, AV_LOG_ERROR, "Invalid chapter start (%"PRId64") or end (%"PRId64").\n", @@ -2026,17 +2027,18 @@ static int mkv_write_chapters(AVFormatContext *s) goto fail; } - chapteratom = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERATOM, 0); - put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERUID, uid); - put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMESTART, chapterstart); - put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMEEND, chapterend); + ebml_writer_open_master(&writer, MATROSKA_ID_CHAPTERATOM); + ebml_writer_add_uint(&writer, MATROSKA_ID_CHAPTERUID, uid); + ebml_writer_add_uint(&writer, MATROSKA_ID_CHAPTERTIMESTART, chapterstart); + ebml_writer_add_uint(&writer, MATROSKA_ID_CHAPTERTIMEEND, chapterend); if ((t = av_dict_get(c->metadata, "title", NULL, 0))) { - chapterdisplay = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERDISPLAY, 0); - put_ebml_string(dyn_cp, MATROSKA_ID_CHAPSTRING, t->value); - put_ebml_string(dyn_cp, MATROSKA_ID_CHAPLANG , "und"); - end_ebml_master(dyn_cp, chapterdisplay); + ebml_writer_open_master(&writer, MATROSKA_ID_CHAPTERDISPLAY); + ebml_writer_add_string(&writer, MATROSKA_ID_CHAPSTRING, t->value); + ebml_writer_add_string(&writer, MATROSKA_ID_CHAPLANG , "und"); } - end_ebml_master(dyn_cp, chapteratom); + ret = ebml_writer_write(&writer, dyn_cp); + if (ret < 0) + goto fail; if (tags && mkv_check_tag(c->metadata, MATROSKA_ID_TAGTARGETS_CHAPTERUID)) { ret = mkv_write_tag(mkv, c->metadata, tags, NULL, |