27595 Commits
Author SHA1 Message Date
Romain Beauxis 23fccd657c avformat/mp3enc: keep trailing padding spanning several packets
The trailing padding is read from the AV_PKT_DATA_SKIP_SAMPLES side data of
every packet, overwriting the previous value, so only the last packet was
ever accounted for. A single packet holds at most one frame, which caps the
padding that can be written at 1152 + 528 + 1 samples.

LAME regularly reports more than that: gapless/gapless.mp3 carries 1984 and
comes out of a stream copy with 1681, decoding to 303 samples more than the
file it was copied from.

Accumulate instead, and add the decoder delay once the total is known.

Fixes: https://trac.ffmpeg.org/ticket/9755
2026-08-07 21:18:03 +00:00
Michael Niedermayer d3ad8a7fee avformat/rawutils: reject raw RGB frames that do not fit an AVPacket
Fixes: integer overflow
Fixes: out of array access
Fixes: payload.film
Fixes: czK1F83k3zvT
Found-by: Clouditera Security, Z.ai Security, NSFOCUS
2026-08-03 13:51:52 +02:00
Romain Beauxis 146e0f7b79 avformat/mp3enc: fix underflow of the LAME encoder delay
AV_RL32() is unsigned, so a skip_samples value below 528 + 1 wraps around
instead of clamping to zero and is written out as a delay of 4095 samples.
2026-08-03 01:54:44 +00:00
Michael Niedermayer ae0e0ba3c3 avformat/mov: reject a trun sample count the input cannot hold
Fixes: OOM
Fixes: 525088811/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5229499332231168
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
2026-08-02 16:05:57 +00:00
James Almer d9da090b1d avformat/dashdec: don't stop at the first input EOF
The current logic would stop demuxing the entire manifest once the first Representation
returned EOF, which could result in plenty of packets from other Representations being
lost.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-08-01 19:47:08 -03:00
James Almer d2476bfd2b avformat/iamf_parse: bound the output mix gain duration by the audio elements
Based on a patch by Michael Niedermayer

Fixes: unbounded allocation
Fixes: poc_output_mix_config_dos.iamf
Fixes: 387qWpjUgeKH
Found-by: Duong Tran Thai (CyStack)
Signed-off-by: James Almer <jamrial@gmail.com>
2026-08-01 19:44:49 -03:00
James Almer 1b946a3abd avformat/iamf_parse: check that num_sub_mixes and num_audio_elements in Mix Presentations are not zero
As required by the spec in Section 3.7

Signed-off-by: James Almer <jamrial@gmail.com>
2026-08-01 19:44:49 -03:00
shadowcaster3 ad53728984 avformat/mpegtsenc: add mpegts_pcr_pid option for separate PCR PID
Add a new muxer option mpegts_pcr_pid that generates PCR on a dedicated
adaptation-field-only PID, separate from any elementary stream.

ISDB-T 1seg receivers require PCR on a standalone PID. When PCR shares
the video PID, these receivers acquire the service but refuse to decode
video and audio. This is standard practice in Japanese digital
terrestrial broadcasting per ARIB TR-B14.

When mpegts_pcr_pid is set to a valid PID value:
- PCR packets are generated as adaptation-field-only packets on the
  specified PID at the interval set by pcr_period
- The video stream adaptation fields do not carry PCR flags
- The PMT PCR_PID field is set to the specified PID

When mpegts_pcr_pid is -1 (default): existing behavior is unchanged.

The existing mpegts_insert_pcr_only function is refactored into a
parameterized mpegts_insert_pcr_only_pid(s, pid, cc, discontinuity)
to avoid code duplication.

Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/23649
Signed-off-by: shadowcaster3 <vasyl.samoilov@gmail.com>
2026-07-31 06:25:59 +00:00
Abdessamie a441a2eb38 avformat/rtsp: clear authentication on cross-origin redirects
RTSP redirects retain URL credentials and authentication state when a
Location URI changes to another origin. This can forward reusable
credentials to a server with a different scheme, host, or port.

Clear the stored credentials and authentication state when the redirect
crosses an origin boundary. Preserve them for same-origin redirects.

Fixes: cross-origin credential disclosure
Fixes: rtsp_redirect_auth_leak_poc.py
Fixes: VaKaPOnfN02z
2026-07-31 04:01:32 +00:00
Michael Niedermayer a100d346da avformat/mov: bound sgpd sync entry_count by the atom size
Fixes: unbounded allocation
Fixes: ffmpeg-sgpd-sync-entry-count-alloc.mp4
Fixes: 4f7OaHqbUKh2
Found-by: Brian Lee, Youngjoon Kim (Georgia Tech SSLab)
2026-07-30 00:13:05 +00:00
panboxiaosa b57a3d028d avformat/mov: set video packet durations in presentation order
STTS sample deltas follow decode order, while AVPacket.duration is
defined as the interval to the next PTS in presentation order. Assigning
the deltas directly therefore produces incorrect packet durations for
VFR video with reordered frames.

After index construction and edit-list processing, sort samples by PTS
and set every duration with a following PTS from adjacent presentation
timestamps. This reorders STTS durations where possible and derives
intervals produced by the STTS/CTTS combination when necessary. Keep the
original timing table if allocation fails or timestamps are invalid.

Add FATE coverage for the official VFR H.264 sample and for a generated
MPEG-4 case whose presentation intervals are not a permutation of its
STTS deltas. Update the HEVC dts2pts CRA reference for the corrected
presentation-order durations.

Signed-off-by: panboxiaosa <panboxiaosa@gmail.com>
2026-07-29 23:49:33 +00:00
almogyalin 04ecca792f avformat/iamf_parse: fix inverted subblock duration validation
The check on variable subblock durations had an inverted comparison, rejecting valid multi-subblock parameters and failing to catch subblock durations exceeding the remaining time.
2026-07-29 21:08:37 +00:00
Omkhar Arasaratnam 83c6922826 avformat/tls_openssl: bind peer identity for numeric-IP verify
tls_open() installed a peer-identity target only when the URL host was
non-numeric. For a numeric-IP target the whole block was skipped, so
with verify=1 OpenSSL validated the chain to a trusted CA but bound no
identity, and any publicly-trusted certificate for any name was accepted
(e.g. tls://203.0.113.10?verify=1).

Run the identity block for every non-listening connection. Classify
s->host with the same getaddrinfo(AI_NUMERICHOST) rule tls.c uses. A
numeric host is pinned to the certificate's iPAddress SAN by handing
OpenSSL the parsed binary address via X509_VERIFY_PARAM_set1_ip();
everything else, including a verifyhost=<name> override, binds by name
via SSL_set1_host(). Passing the binary address rather than re-probing
the ASCII form pins legacy numeric spellings such as 2130706433 as IPs
instead of letting them fall back to hostname matching. SNI is still
suppressed for numeric transport hosts (RFC 6066 sec. 3) via
s->numerichost.

The identity target is installed unconditionally for non-listening
connections; whether the certificate is actually verified stays
controlled separately by SSL_CTX_set_verify() under s->verify, so
disabling verification keeps the prior behaviour. Sets AVERROR_EXTERNAL
with an explicit log line on failure.

dtls_open() sets s->is_dtls and then calls tls_open(), so DTLS client
connections run through the same identity block and are covered here.

Found-by: Claude (Anthropic). Human-verified and reported by
Omkhar Arasaratnam <omkhar@linkedin.com>.
Signed-off-by: Omkhar Arasaratnam <omkhar@linkedin.com>
2026-07-29 20:37:16 +00:00
Michael Niedermayer 2b7e501242 avformat/codec2: avoid integer overflow in packet size and duration
Fixes: signed integer overflow
Fixes: 2jy_poc_codec2.zip / poc_codec2.raw
Fixes: jOQASNnOm6O7
Found-by: Jiale Yao <yaojiale02@163.com>
2026-07-29 02:03:25 +00:00
Kacper Michajłow f6fa0d3fda avformat/hls: refine first_timestamp from the first segment's packets
first_timestamp is taken from the first packet in mux order, which is
not necessarily the earliest timestamp in the segment. Lower it while
packets of that segment are still arriving, so the seek timeline is
anchored at the true segment start.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 18:01:18 +02:00
Kacper Michajłow 848fb754dd avformat/hls: don't discard target segment's first keyframe when seeking
Segment starts on the seek timeline are derived from EXTINF durations,
so the first keyframe of the target segment can have a slightly lower
DTS than the snapped seek position, in which case the packet discard
loop would skip it and resume playback one segment late. Make sure we
start at the very beginning of the stream in this case.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 18:01:18 +02:00
Kacper Michajłow 84bc576371 avformat/hls: set stream start_time for all playlist types
Rebase the first packet's timestamp onto the start of the segment list
regardless of playlist type, and report it as start_time. Previously
only EVENT playlists did this and live streams took start_time from the
first loaded segment at the live edge. Which is not correct as some
servers provide very deep (hours even) time shift in live playlist. The
evicted segments are already tracked by EXT-X-MEDIA-SEQUENCE. This
allows us to use all available segments, not only the future ones on
live playlist.

Also prefer PTS over DTS, as EXTINF durations and start_time are
presentation time.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 18:01:18 +02:00
Kacper Michajłow ede944b362 avformat/hls: allow seeking within live playlists
Live (and EVENT) playlists are seekable within the currently known
segment list. Seeks before the list start clamp to the oldest segment,
past the end to the live edge. Live playlist can evict old segments, we
track that by reading EXT-X-MEDIA-SEQUENCE. Previusly the code assumed
that the live playlist, don't have past segments, however some servers
has very deep usable timeshift.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 18:01:18 +02:00
Kacper Michajłow 2526ac4771 avformat/hls: use av_rescale_q instead of doing only denominator 2026-07-28 18:01:17 +02:00
Kacper Michajłow e822dd253b avformat/hls: remove else after break
To reduce unnecessary nesting.
2026-07-28 18:01:17 +02:00
Kacper Michajłow ff818b87bf avformat/mpeg: fix demuxing of DVD-Audio LPCM
Substream 0xa0 packets without the DVD-Video dynamic range control
marker byte were assumed to be MLP, while in DVD-Audio AOBs substream
0xa0 always carries LPCM (MLP uses 0xa1), so hi-res LPCM streams were
misdetected and decoded as garbage. Classify them as PCM_DVDA and keep
the private stream header in the packet for the decoder to parse, as
its length is variable and it carries the audio format.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 17:55:33 +02:00
Christopher Decker 94ff335d76 avformat/os_support: fix return value of win32_rename
The return value of MoveFileExW was not being correctly interpreted,
see https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexw.

On Windows a failed rename over the file: protocol now surfaces as failed to rename file %s to %s:
Operation not permitted (ff_rename, libavformat/avio.c:867) plus an AVERROR(EPERM) return, where previously the muxer
reported success and the user was left with a missing or stale output file and no diagnostic. This affects the
write-to-temp-then-rename paths in hlsenc, dashenc, hdsenc, smoothstreamingenc, segment, and img2enc (e.g. HLS/DASH
playlist updates, -write_temp_file, segment list finalization).

Also, added unit tests to exercise the rename function.

Signed-off-by: Christopher Decker <chris.decker08@gmail.com>
2026-07-28 04:59:01 +00:00
Kacper Michajłow 298f67fa2a avformat/libcurl: fix comments
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow d097f9385f avformat/libcurl: limit buffer_size to INT_MAX
Larger values silently truncate on 32-bit, which can make the resulting
FIFO too small to ever satisfy the unpause threshold.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow 6d626c1a3c avformat/libcurl: fix AVBPrint leak on setup_protocols() error paths
The API is not clear to me if AVBPrint has to be finalized on errors,
but there is nothing wrong to be defensive here

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow 798fb1f9aa avformat/libcurl: clear the pause flag when unpausing
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow c2b0152ad3 avformat/libcurl: keep the seekable user override across replies
It was applied once after the probe, from the wrong thread, and any
follow-up reply re-evaluating seekability discarded it.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow be6b6743b8 avformat/libcurl: improve content size tracking
Track the size for non-seekable replies too, don't reset a known size when
a reply omits it, and don't store the encoded length of a compressed body.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow aec0c7a0cb avformat/libcurl: only offer compression for full unbounded requests
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow 723a855e52 avformat/libcurl: validate that the server honored a requested start offset
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Niklas Haas cbed990021 avformat/libcurl: guard against unexpected reply content-range
Harden against malicious or badly misbehaving servers.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 488061b9cb avformat/libcurl: guard against overflow from over-reading data
In theory a client could be coaxed by a malicious server to seek to a
large 64-bit offset, which would then trigger an overflow of the position.

Better safe than sorry and just error out with EIO in such cases.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 337b884a4e avformat/libcurl: guard against integer overflow on start_request()
The failure mode here is to just request the rest of the file, which is
explicitly safe.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas fea5d3ccc3 avformat/libcurl: guard against overflow on seek()
Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 2a6514b7c4 avformat/libcurl: harden against malicious underflow
If the server sends a value of INT64_MIN here, we would correctly parse
it and then subtract off -1, underflowing to a huge positive value
(and triggering undefined behavior in the process).

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 6150323029 avformat/libcurl: use int64_t consistently
Instead of randomly mixing in uint64_t. As far as I can tell, we don't
depend on defined overflow behavior anywhere, except where such would be a
bug anyways, and I'm also pretty sure we won't exhaust the 63-bit file size
limit of int64_t any time soon, so this is just a footgun prevention
mechanism.

We already have a few dodgy places of mixing int64_t and uint64_t values
in the code haphazardly.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 7530aa12ee avformat/libcurl: avoid integer overflow in connect_timeout
This is multiplied by 1000, which can overflow on systems with 32-bit
long (i.e. most of them).

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 946a450cec avformat/libcurl: implement -initial_request_size
See corresponding feature in http.c.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas d754fb37a5 avformat/libcurl: simplify continuation decision logic
Instead of trying to statically guess whether or not we expect more data
to be available by exactly recreating the logic, we can consult the parsed
content-range header directly to determine if there are more bytes in the
file.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 34015e179d avformat/libcurl: fully parse Content-Range header
Logic copied from http.c

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 90a08d3657 avformat/libcurl: early exit on no-op seek
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas d993f37a1b avformat/avio: propagate prefer_libcurl preference from parent URLContext
Since this is consumed by e.g. protocols which open inner protocols.
This would normally be propagated by the `av_opt_copy` call, but as this
check happens *before* the inner URLContext is even allocated, we're
forced to propagate the options manually.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas cee0613cf7 avformat/libcurl: track and report connection/request statistics
In theory, we could expand this a lot more, by adding more verbose
statistics about individual request latency etc, but I don't think that's
as helpful (to me) as at least tracking the number of requests made.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 835ebef535 avformat/libcurl: keep track of owning AVFormatContext
For avfc-attached curl loops.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas b5bf0a1a87 avformat/hls: check if http protocol is native or not
When using -prefer_libcurl, http might be served by libcurl instead of the
native HTTP backend; in this case we shouldn't use `ff_http_do_new_request2`
and instead create a new request.

I added a few assertions to safeguard some of the assumptions this code
clearly relies on.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 45c4f59eb2 avformat/aviobuf: add prefer_libcurl to ffurl_copy_url_options()
Otherwise this doesn't reach e.g. the inner HTTP requets made by HLS etc.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas b737bddaf1 avformat/avio: re-use av_opt_set() to parse prefer_libcurl
Otherwise, this fails to parse values like "true" or "yes". This does
require stack-allocating a dummy object, but that's not a big deal, as
we only ever set this single option on it, so nothing should ever
get allocated.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas e11cec1059 avformat/libcurl: respect format whitelist
And also set a reasonable default whitelist. This is especially important
because libcurl supports a much wider range of protocols than FFmpeg,
including e.g. smtps, telnet, gopher, etc.

We have to include "libcurl" in libcurl's own default whitelist, otherwise
it will refuse te recursively open itself for e.g. HLS.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas c70d777f7f avformat/libcurl: enable cookie engine unconditionally
With the previous commit, this allows cookies to persist across requests.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas 6c338a6595 avformat/libcurl: attach a CURLSH shared handle to all requests
This allows sharing cookies, HSTS state etc. between requests inside a single
AVFormatContext. This is analogous to the status quo of http.c, which also
re-uses cookies across all requests.

Note that the connection state, DNS cache, SSL session etc. are shared by
default when using a multi handle, so we only need to explicitly share the
rest.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00