Skip to content

stream_libarchive: don't corrupt the stream position on a failed seek - #18795

Merged
kasper93 merged 6 commits into
mpv-player:masterfrom
kasper93:libarchive-fix
Nov 10, 2026
Merged

kasper93 merged 6 commits into
mpv-player:masterfrom
kasper93:libarchive-fix

Conversation

@kasper93

@kasper93 kasper93 commented Nov 9, 2026

Copy link
Copy Markdown
Member

No description provided.

archive_seek_data() returns the new position as la_int64_t. Fixes
seeking > 2 GiB to not read everything from start.
The skip callback may skip less than requested, so bound the request by
what the position can hold.
The stream layer keeps its buffer and s->pos when the seek callback
fails, but archive_entry_seek() moved s->pos while reopening the archive
and while reading forward. After a failed seek stream_tell() reported an
offset unrelated to the buffered data.

Track the entry position locally and let the stream layer set s->pos
after a successful seek only.
The seek callback is documented to return ARCHIVE_FAILED when the seek
failed without moving the read position and ARCHIVE_FATAL for any other
error.
Entry names in a legacy codepage arrive from libarchive as raw bytes
and were replaced by mpv_unknown#N when they weren't valid UTF-8. Run
them through the mp_charset_guess().

libarchive's UTF-8 form of a name is used only when the plain form is
missing. On Windows that is the case for Unicode names the C locale
can't represent, while for raw names the UTF-8 form was a Latin-1
decode of the bytes, which hid them from any detection. Names that are
valid UTF-8 are never recoded, so a forced codepage applies to the raw
ones only.
@kasper93
kasper93 merged commit d075ec2 into mpv-player:master Nov 10, 2026
34 checks passed
@kasper93
kasper93 deleted the libarchive-fix branch November 10, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant