demux_edl allocates metadata track with type set to STREAM_TYPE_COUNT,
when counting track types this was not accounted for. Make room for this
"special" type of track. Add asserts while at it, just in case.
Note that other similar uses are gated behind track->selected, and
metadata track will never be marked as one.
This is not exploitable, as it was overriding only one integer value past
the allocated array, so worse thing that could happen is that we
misbehave during track selection or crash.
Side note, OSS-Fuzz was fuzzing this for few years now, and couldn't dig
into this specific case. I've validated that our fuzzer is in fact
reproducing this issue when provided the testcase, which I belive was a
basis for this report.
Fixes: GHSA-qpf4-42gw-f286
This vulnerability was discovered by Claude, Anthropic's AI assistant,
with OSS-Fuzz fuzzing and triaged by Ada Logics manually in
collaboration with Anthropic Research.
Lavf exposes programs/renditions as a flat track list tagged with
program_id. We respect this metadata and group tracks into their
respective programs, as tracks from different programs may be completely
unrelated to each other.
This commits adds an option to flatten the editions and ignore the
grouping.
Fixes: https://github.com/mpv-player/mpv/issues/17836#issuecomment-4345930205
When the current edition supplies its own track of a given type
(e.g. yt-dlp muxed editions ship their audio paired with the video),
shared program_id == -1 tracks of that type are filtered out of
both the track list and auto-selection. Editions that don't ship
their own track (DASH video-only editions sharing the audio pool)
continue to see the program-agnostic tracks.
This adds proper support for MPEG-TS programs and HLS variants. Now
program selection is exposed as editions and tracks are grouped under
such edition. If there are external tracks added, they are available in
all editions.
Currently, there is no hook which happens when the playback actually
starts. The on_preloaded hook is insufficient for many cases, as many
track information are unavailable at that stage. This makes it impossible
to act on certain track metadata before the media is shown to the user,
so the user will see the media before action for a brief moment before the
properties are notified and options are changed.
This adds the on_loaded hook which allows the mentioned information
available.
If you set file-local-options/foo at runtime and run playlist-play-index
current or playlist-play-index $current_pos, file-local-options/foo is
reset. Add a flag to make it preserve file-local-options.
The advantage of this change is that it allows binding Ctrl+r set
file-local-options/start ${=time-pos}; playlist-play-index current yes
to reload the current file while preserving all options, independently
of --no-config, --watch-later-options or --reset-on-next-file, and
without writing watch later files to disk. It also preserves
file-local-options set on the CLI unlike loadfile.
Scripts and things using the client API can load up playlists in a
specific order and choose what file to start playing on by using the
loadfile or loadlist commands with the play argument. However if
starting from idle mode, it is possible to send these commands before
all scripts finish initializing. mpv's core then does a prepare_playlist
call on its own for startup which will nuke the current playlist entry
set by the API user and lead to an unexpected item being played. Fix
this by not unconditionally setting pl->current to NULL allow callers to
optionally always overwrite it by getting the first item in the playlist
(e.g. if it's called after startup anywhere else in the code). Other
options like --playlist-start or --shuffle are allowed to win if they
happen to be set.
Currently, we prefer selecting a track that matches the video program
ID, but can fall back on a track with a different program ID when there
is no such track or when no such track matches subs-fallback criteria.
Change this to instead select no track when only tracks with wrong PID
are available. Program ID will now act as a filter, not as a preference,
and only files with either matching or unset PID will be considered for
autoselect.
Also, ignore the program ID of external tracks, as it doesn't make much
sense to compare PIDs from different files.
When autoload-files=no, external files are never selected. Simplify the
logic by excluding them up front instead of removing them afterwards.
This doesn't change the outcome of track selection, apart from edge
cases that are already broken because compare_track is not transitive.
This fixes the problem that a subtitle track that normally wouldn't be
selected if it were the only track available could end up being selected
after a different candidate track was selected first.
Use track->forced_select instead. The value would be assigned there
anyway after the track is selected and the field is not used for any
other purpose.
It's a pretty niche case, but if you start a file with no video with
animated ass subtitles and then turned on the video later, the subtitles
would not actually be rendered animated. This because the subtitles were
already decoded, and we do not do a check for animations expect in the
specific case of an image being played back on the video since the check
can be quite expensive. To fix this edge case, we just need to reset the
ass before doing the track switch in the case where we go from no video
to a track that's an image. SD_CTRL_RESET_SOFT is added as a a sub_ctrl
to accomplish this. Fixes#17268.
Since the previous commit normalized playlist filenames when they are
stored, the code normalizing them can be simplified back to how it was
before implementing normalization.
Since the option system now handles all the path expansion
automatically, these recent changes can be reverted for simplicity.
This reverts commit be15be3a83.
Useful for demux_edl where it is possible to have huge nested tree of
demuxers and they are added recursively, which causes stack overflow in
some cases.
Found by OSS-Fuzz.
For matching the audio language with the track subtitle language,
strcasecmp is insufficient since it only allows exact matches and misses
the language regional variant. Fix this by simply using mp_match_lang
instead.
Fixes#16461.
There's several path-related options that do not handle common shortcuts
(like ~/). Fix this by using mp_get_user_path where appropriate which
expands the path so users get more intuitive behavior. Fixes#15598.
This ensures that we don't open some other fd, for example when loading
playlist. Also filters out loading any local files.
This also allows to remove custom filtering from fuzzer itself.
When using --prefetch-playlist, if demuxer options are changed in the
time window between the start of prefetching and the playback of the
next file, the old values are used. This includes setting demuxer
options in legacy extension auto profiles.
Fix this by setting a flag when demuxer options change and not using the
prefetched data when that flag is true.
UPDATE_DEMUXER is not added to demux.c's options because those already
support updates while playing.
The history could be formatted as CSV, but this requires escaping the
separator in the fields and doesn't work with paths and titles with
newlines. Or as JSON, but it is inefficient to reread and rewrite the
whole history on each new file, and doing so overwrites the history with
an empty file when writing without disk space left. So this uses a
hybrid of one JSON object per line to get the best of both worlds. This
is called NDJSON or JSONL.
Co-authored-by: Kacper Michajłow <kasper93@gmail.com>
With this combination of options, the playlist is shuffled every time
the last playlist is reached, instead of when restarting from the first
playlist entry. Abort prefetching in this case, as we can't predict
which file to prefetch until the playlist is shuffled when actually
going to the first file again.
With --prefetch-playlist and --loop-playlist, mp_next_file() is called
continously since the last second of playback or when viewing an image,
which decreases --loop-playlist=N to 1.
Fix this by adding a flag to mp_next_file() to specify whether to
decrement --loop-playlist=N. The first playlist entry is still
prefetched when it's the next one, but without decrementing
--loop-playlist=N.
Dependent tracks are supposed to be processed further and not directly
used.
For example, an HEIF tiled image tracks are meant to be stitched into a
full image before being displayed and requires special handling.
Another example would be MPEG-TS audio track tagged with mix_type=0.
Which means that the audio stream is a dependent stream and is intended
to be mixed or combined with a separate complete and independent audio
stream by the receiver.
In either case we should not directly select such tracks.
This fixes `ytdl_hook`, which would start playback with the thumbnail
track selected. This issue occurs because the thumbnail track is added
first. If the main track is not marked as default afterward, which it
isn't for single streams, the first track (the image track) would be
selected.
In general, if a non-image track is available, it should be preferred.