Commit Graph

514 Commits

Author SHA1 Message Date
Kacper Michajłow 6bdacac991 player/loadfile: fix stack-overflow on EDL metadata track
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.
2026-05-12 13:09:22 +02:00
Kacper Michajłow f5857d3b87 demux_lavf: support multiple program mappings per stream
Each stream can belong to multiple programs, we have to support that.
Previously track could belong only to single program.
2026-05-01 11:41:31 +02:00
Kacper Michajłow eedadc24ae player/command: hide dependent tracks
They are unusable on thier own, and shouldn't be selected by the user.
Those tracks are ment to be used internally.
2026-05-01 10:42:00 +02:00
Kacper Michajłow b4a7ea306e demux_{lavf,timeline}: add --flatten-editions
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
2026-05-01 10:42:00 +02:00
Kacper Michajłow 3e3936eee4 player/loadfile: filter tracks without edition when there are matches
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.
2026-04-29 03:45:05 +02:00
Kacper Michajłow 4730c9179a player/loadfile: remove preferred_program from track selection
It's no longer needed, tracks from different editions are not listed
togheter anymore.
2026-04-29 03:45:05 +02:00
Kacper Michajłow 6c165fe46e demux_lavf: add support for programs
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.
2026-04-17 18:30:43 +02:00
nanahi ba30c8c175 player/loadfile: add on_loaded hook
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.
2026-03-08 13:07:05 +01:00
Guido Cella 3b555c349c command: let playlist-play-index current preserve file-local-options
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.
2026-02-27 09:21:14 +01:00
Simon Bruder 534b2d2ea6 {demux,player}: expose original and commentary track flags
Those flags were added to the Matroska specification together with the
already implemented hearing-impaired and visual-impaired flags.

They allow specifying whether a track is a commentary track or in the
original language without relying on the free-form track name, which
makes consistent tagging and parsing by machines easier.

Ref: https://github.com/ietf-wg-cellar/matroska-specification/pull/447
Ref: https://www.rfc-editor.org/rfc/rfc9559#name-original-flag
Ref: https://www.rfc-editor.org/rfc/rfc9559#name-commentary-flag
2026-02-20 20:31:04 +01:00
Dudemanguy 76a5eba991 player: don't mangle current playlist entry before initialization
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.
2026-02-12 04:42:32 +00:00
Filip Hejsek c2882c3d81 player/loadfile: never autoselect tracks with wrong PID
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.
2026-01-24 07:54:46 +01:00
Filip Hejsek 6bae2c0f53 player/loadfile: simplify how external tracks are excluded
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.
2026-01-24 07:54:46 +01:00
Filip Hejsek a6cb319611 player/loadfile: simplify track selection logic
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.
2026-01-24 07:54:46 +01:00
Filip Hejsek 82dce233bc player/loadfile: clean up track comparison logic
This brings compare_track closer to implementing a consistent linear
order and fixes many broken edge cases.
2026-01-24 07:54:46 +01:00
Filip Hejsek 8d5fcade02 player/loadfile: remove forced param from compare_track
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.
2026-01-24 07:54:46 +01:00
Dudemanguy 49b6d80e87 player/loadfile: possibly do a reset of sd_ass when turning on video
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.
2026-01-21 15:18:08 +00:00
Guido Cella fc86b96a8a various: don't normalize playlist filenames again
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.
2026-01-12 15:10:37 +00:00
Kacper Michajłow 273f1db49e player/loadfile: indent file metadata if it is multiline
And sanitize a bit.
2026-01-06 13:57:21 +01:00
Dudemanguy 2b74582fcb Revert "various: remove unneeded option path expansion handling"
Fixes #16573.

This reverts commit 137d5374bd.
2025-08-08 01:07:00 +00:00
Dudemanguy 29307c26ba Reapply "various: expand paths for all file/directory related options"
This reverts commit 43fda5442f.
2025-08-08 01:07:00 +00:00
Dudemanguy 137d5374bd various: remove unneeded option path expansion handling
Same reasoning as the previous commits. This is now handled by the
option system so we can remove the redundancy.
2025-07-22 17:52:41 +00:00
Dudemanguy 43fda5442f Revert "various: expand paths for all file/directory related options"
Since the option system now handles all the path expansion
automatically, these recent changes can be reverted for simplicity.

This reverts commit be15be3a83.
2025-07-22 17:52:41 +00:00
Kacper Michajłow fec62de298 demux: add nested demuxer depth limit
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.
2025-07-12 01:57:43 +02:00
Kacper Michajłow 9baadc6cc9 player/loadfile: limit playlist length to 3 for fuzzing
We have 5 seconds limit for file playback, so 10 items it's bit much. 3
should be enough to cover some file switching and so on.
2025-07-09 00:08:37 +02:00
dyphire 2d149e007f misc/language: parse default tag from external subtitle tracks 2025-07-06 12:52:22 +02:00
Dudemanguy 580f2ecbd5 player/loadfile: match audio and subtitle language with mp_match_lang
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.
2025-06-19 20:18:02 +00:00
sfan5 9db49973f2 misc/path_utils: check existence first in mp_mkdirp() 2025-06-02 15:59:05 +02:00
sfan5 013e76e1c0 player: create missing folders for watch-history-path
fixes: #16357
2025-06-02 15:59:05 +02:00
Tom Grimwood-Taylor f608780032 misc/language: parse forced tag from external subtitle tracks
Fixes: mpv-player#16060
2025-03-31 11:47:52 +02:00
Kacper Michajłow 7b9290f620 player/command: add visual-impaired flags to track add command 2025-03-08 00:21:06 +01:00
Kacper Michajłow 7df3f442ea misc/language: parse hi/sdh/cc tags from external subtitle tracks
This also adds `hearing-impaired` argument to `sub-add` command.

Fixes: #14805
2025-03-08 00:21:06 +01:00
Kacper Michajłow 25fa0bd08a player/loadfile: fix history_file leak 2025-03-06 21:58:38 +01:00
Kacper Michajłow 1c49cfdb97 various: use mp_assert macro 2025-03-04 20:07:29 +01:00
Kacper Michajłow 57210dfc4b player/loadfile: strip common filename part from external track title
It's most of the time redundant and there is no point to repeat it in
`title`.
2025-02-24 16:18:05 +01:00
Kacper Michajłow 77313f73a2 various: reduce the include scope of some public headers 2025-02-23 01:40:12 +01:00
Dudemanguy 23b57e9f7f player: store external filenames as normalized
Instead of re-normalizing the external filenames of tracks anytime the
property is read, store it normalized in the first place.
2025-02-17 16:33:30 +00:00
Kacper Michajłow d739df9ec3 player/loadfile: don't use ta_set_parent directly 2025-02-14 15:21:02 +01:00
Kacper Michajłow 3717a530ca player/loadfile: we shouldn't unescape inplace
I got mesmerized by the simplicity of the original commit, but in fact
it was not a correct thing to do.

Fixes: c0366cfa42
2025-02-05 18:04:11 +01:00
Nikolai Vavilov c0366cfa42 loadfile: unescape display filenames
This makes OSD more usable when the filename contains non-ASCII characters.
2025-02-05 05:04:33 +01:00
Dudemanguy be15be3a83 various: expand paths for all file/directory related options
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.
2025-01-29 14:49:06 +00:00
Kacper Michajłow 1d352f8527 stream_file: allow to open only our fd in case of fuzzing
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.
2025-01-28 07:59:04 +01:00
Guido Cella 24db17d10f loadfile: discard prefetched files if demuxer options changed
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.
2025-01-27 19:32:52 +00:00
Guido Cella b75ed73f4f loadfile: optionally save the watch history
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>
2025-01-27 18:53:28 +01:00
Guido Cella df3872e318 loadfile: fix --loop-playlist + --shuffle + --prefetch-playlist
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.
2025-01-22 14:01:11 +00:00
Guido Cella 304a620b0b loadfile: return earlier if prefetch already started
There is no need to call mp_next_file() if prefetching already started,
so return earlier.
2025-01-22 14:01:11 +00:00
Guido Cella e7a253614c loadfile: fix --loop-playlist=N with --prefetch-playlist
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.
2025-01-22 14:01:11 +00:00
Kacper Michajłow ad1fb9f448 player/loadfile: prefer independent track when selecting track
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.
2024-11-26 11:42:48 +01:00
Kacper Michajłow 3e10309b62 player/loadfile: prefer non-image when selecting video track
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.
2024-11-22 21:14:52 +01:00
Kacper Michajłow e96bffe7a8 player/loadfile: limit playlist size to 10 for fuzzing
Fixes timeout on huge generated playlists, 10 is enough to test if it
works.
2024-11-02 01:40:41 +01:00