mirror of https://github.com/mpv-player/mpv
demux: check embedded cuesheet refers to only one file
If someone was "clever" enough to embed a cuesheet referencing multiple files, mpv would create a bunch of nonsense chapter markers.
This commit is contained in:
parent
ad80cc4eee
commit
7137afeb2c
15
demux/cue.c
15
demux/cue.c
|
@ -218,3 +218,18 @@ struct cue_file *mp_parse_cue(struct bstr data)
|
|||
|
||||
return f;
|
||||
}
|
||||
|
||||
int mp_check_embedded_cue(struct cue_file *f)
|
||||
{
|
||||
char *fn0 = f->tracks[0].filename;
|
||||
for (int n = 1; n < f->num_tracks; n++) {
|
||||
char *fn = f->tracks[n].filename;
|
||||
// both filenames have the same address (including NULL)
|
||||
if (fn0 == fn)
|
||||
continue;
|
||||
// only one filename is NULL, or the strings don't match
|
||||
if (!fn0 || !fn || strcmp(fn0, fn) != 0)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -38,5 +38,6 @@ struct cue_track {
|
|||
|
||||
bool mp_probe_cue(struct bstr data);
|
||||
struct cue_file *mp_parse_cue(struct bstr data);
|
||||
int mp_check_embedded_cue(struct cue_file *f);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -926,10 +926,15 @@ static void demux_init_cuesheet(struct demuxer *demuxer)
|
|||
if (cue && !demuxer->num_chapters) {
|
||||
struct cue_file *f = mp_parse_cue(bstr0(cue));
|
||||
if (f) {
|
||||
for (int n = 0; n < f->num_tracks; n++) {
|
||||
struct cue_track *t = &f->tracks[n];
|
||||
int idx = demuxer_add_chapter(demuxer, "", t->start, -1);
|
||||
mp_tags_merge(demuxer->chapters[idx].metadata, t->tags);
|
||||
if (mp_check_embedded_cue(f) < 0) {
|
||||
MP_WARN(demuxer, "Embedded cue sheet references more than one file. "
|
||||
"Ignoring it.\n");
|
||||
} else {
|
||||
for (int n = 0; n < f->num_tracks; n++) {
|
||||
struct cue_track *t = &f->tracks[n];
|
||||
int idx = demuxer_add_chapter(demuxer, "", t->start, -1);
|
||||
mp_tags_merge(demuxer->chapters[idx].metadata, t->tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
talloc_free(f);
|
||||
|
|
Loading…
Reference in New Issue