Commit graph

27356 commits

Author SHA1 Message Date
James Almer
de647bfbbc avformat/mpeg: lower PES stream score compared to mp3/ac3
The heuristics run to detect PES streams are much laxer than mp3/ac3 ones,
which check for valid headers, so it should not have a higher score than the
latter.

Fixes misdetection of some mp3 files with big id3v2 tags at the beginning.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-31 00:39:51 +00:00
James Almer
fd9e4fa081 avformat/dump: remove unused variable
Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-30 16:02:26 -03:00
Romain Beauxis
6ef1a9579f avformat/matroskaenc: write hvcE BlockAdditionMapping for Dolby Vision EL
When AV_PKT_DATA_HEVC_CONF is present on an HEVC track, write
an hvcE BlockAdditionMapping alongside the existing dvcC/dvvC one,
carrying the raw HEVCDecoderConfigurationRecord for the enhancement layer.
2026-05-30 17:37:28 +00:00
Romain Beauxis
523b9faa94 avformat/matroskadec: parse hvcE block addition mapping as AV_PKT_DATA_HEVC_CONF
Handle MATROSKA_BLOCK_ADD_ID_TYPE_HVCE in mkv_parse_block_addition_mappings
and store the raw HEVCDecoderConfigurationRecord as
AV_PKT_DATA_HEVC_CONF on the stream's coded side data, mirroring
the existing dvcC/dvvC handling.
2026-05-30 17:37:28 +00:00
Romain Beauxis
e2cfc80f32 avformat/matroska: add hvcE block addition mapping type
Add MATROSKA_BLOCK_ADD_ID_TYPE_HVCE (0x68766345) for the Dolby Vision
enhancement-layer HEVC configuration, alongside the existing dvcC/dvvC
entries.
2026-05-30 17:37:28 +00:00
Romain Beauxis
199e49d9b6 avformat/movenc: write hvcE box for Dolby Vision enhancement layer
When AV_PKT_DATA_HEVC_CONF is present on a MODE_MP4 HEVC
track, write it as an hvcE box alongside hvcC and dvcC. Like dvcC,
writing requires -strict unofficial.
2026-05-30 17:37:28 +00:00
Romain Beauxis
2c74d197ee avformat/mov: parse hvcE box as AV_PKT_DATA_HEVC_CONF side data
The hvcE box carries the HEVCDecoderConfigurationRecord for the Dolby
Vision enhancement layer in ISOM-based containers. Store its raw
contents as AV_PKT_DATA_HEVC_CONF on the stream's coded side data,
mirroring the existing dvcC/dvvC handling.
2026-05-30 17:37:28 +00:00
Michael Niedermayer
aaac0989e6 avformat/mxfdec: Remove unneeded check
size is 16bit only

Found-by: Tomas Härdin
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-29 18:23:06 +00:00
Jerome Berclaz
468a743af1 avformat/dashenc: add options for live MPD timing 2026-05-29 03:25:53 +00:00
Michael Niedermayer
4d24cb1c39 avformat/ftp: Check string used for RNTO
Found-by: Forgejo Fairy
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-29 01:49:20 +00:00
Michael Niedermayer
090838497c avformat/ftp: Check for Telnet IAC characters and other non printable ASCII chars
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-29 01:49:20 +00:00
Franciszek Kalinowski
640f32b1b6 avformat/ftp: reject CR/LF in the URL path to prevent FTP command injection
ftp_connect() interpolates the URL path into SIZE/RETR/STOR/CWD/DELE/RMD/RNFR
commands without checking for CR/LF, although it already rejects CR/LF in the
user and password fields. Reject CR/LF in s->path the same way.

Reported and reviewed by Franciszek Kalinowski (isec.pl / striga.ai) and Bartosz Åšmigielski.
2026-05-29 01:49:20 +00:00
James Almer
93512bc2fd avformat/avc: Adjust get_ue_golomb() to handle 32 bit
Fixes: assertion failure
Fixes: PR-009/bad_extra_idr_only.avi

Found-by: mosskappa
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-28 21:46:48 +00:00
Omkhar Arasaratnam
7b46c6a2a3 avformat/whip: require remote DTLS fingerprint in SDP answer
WHIP relies on the SDP a=fingerprint to bind the peer identity to
the SRTP keying material (RFC 8842 §§ 5.1, 5.3). parse_answer()
walks the SDP body looking for `a=ice-lite`, `a=ice-ufrag:`,
`a=ice-pwd:`, and `a=candidate:` lines and ignores everything else,
including `a=fingerprint`. WHIP intentionally runs the OpenSSL DTLS
backend with s->verify=0 (DTLS-SRTP uses self-signed certs by
design, so a CA chain check would be meaningless); the peer cert is
accepted regardless of identity. The spec's compensating identity
control — verifying the DTLS peer cert against the SDP a=fingerprint
hash — is missing, so the SRTP keys are derived from a session
whose peer identity was never authenticated. Any on-path attacker,
or a malicious WHIP server URL, can substitute their own DTLS
material and the publisher's RTP stream will be encrypted to them.

The full fix is a two-step process:
  (a) Require a=fingerprint to be present in the SDP answer
      (RFC 8842 § 5.3 MUST).
  (b) After DTLS handshake, compute the peer-cert hash and compare
      against the stored fingerprint (RFC 8842 § 5.1 MUST); tear
      down the session on mismatch.
This patch implements step (a) only; step (b) requires plumbing
the cert hash out of dtls_start() through the openssl TLS context
and is left as a follow-up.

Add a remote_fingerprint field to WHIPContext, extract the
a=fingerprint value from the SDP answer in parse_answer(), and
return AVERROR(EINVAL) when it is absent. This raises the bar from
"no fingerprint required" to "any fingerprint required"; the
follow-up patch will raise it again to "fingerprint MUST hash-match
the DTLS peer cert."

Found-by: Claude (Anthropic). Human-verified and reported by
Omkhar Arasaratnam <omkhar@linkedin.com>.
Signed-off-by: Omkhar Arasaratnam <omkhar@linkedin.com>
2026-05-28 04:41:06 +00:00
Tim Walker
c591ddd453 avformat/movenc: don't write a 'chan' atom with an incorrect channel bitmap or description. 2026-05-28 03:22:29 +00:00
Tim Walker
29bb6a771a avformat/movenc: re-order mov_codec_ch_layouts 2026-05-28 03:22:29 +00:00
Tim Walker
55ba902d71 avformat/movenc: re-indent mov_codec_ch_layouts 2026-05-28 03:22:29 +00:00
Tim Walker
d4125bbce7 avformat/movenc: add channel layout mappings for a few codecs
These codecs cannot self-report layout in the bitstream, and
are known or expected to use a libavutil-compatible channel
order, and as such can use mov_ch_layouts_wav for tag lookup.
2026-05-28 03:22:29 +00:00
Vann Harl
fb5dd6ec60 avformat/tls_{openssl,gnutls,mbedtls}: gate DTLS udp helpers on CONFIG_UDP_PROTOCOL
ff_udp_get_last_recv_addr and ff_udp_set_remote_addr are defined in
udp.c which only compiles under CONFIG_UDP_PROTOCOL. Building with
--disable-everything plus a protocol whitelist that excludes UDP
left these references unresolved at link time, even though TLS
itself uses TCP. Wrap the DTLS UDP-remote-addr blocks accordingly
2026-05-27 11:41:32 +00:00
Aditya Banavi
28b92b9b2e avformat/tls_gnutls:fix crash when connecting to peer
When ffmpeg whip client takes up dtls_active role when using gnutls,
it tries to connect to the server over udp and intermittently crashes.
This is because s->host is NULL, and ffmpeg is in ice controlling mode.
The gnutls api - gnutls_server_name_set() crashes if the hostname is NULL.

This commit assigns valid value to s->host in such scenarios.

Signed-off-by: Aditya Banavi <adityabanavi@gmail.com>
2026-05-27 11:39:32 +00:00
Aditya Banavi
df3511db5b avformat/tls: Moved the parsing of host uri into a separate function - ff_tls_parse_host()
This makes the function reusable and modular

Signed-off-by: Aditya Banavi <adityabanavi@gmail.com>
2026-05-27 11:39:32 +00:00
Michael Niedermayer
4945e33e98 avformat/dashdec: bound manifest reloads and fragment-open retries
Mirror the HLS demuxer's max_reload pattern

Reported as a DoS finding by Xueqing. Verified with the supplied PoC
server: a 30s ffmpeg run that previously generated ~10000 requests
without termination now exits in ~100ms after exactly max_reload
fragment-open failures.
2026-05-25 22:35:21 +00:00
Omkhar Arasaratnam
387ad6d102 avformat/mov: validate APV access unit length before passing to decoder
libavformat/mov.c read the APV AU length field directly from the
sample without sanity-checking against the remaining sample size or
a documented maximum. The patch validates that au_size is bounded by
the remaining sample bytes and that the AU envelope (4 bytes plus
au_size) fits inside the declared sample size.

Validate the access unit length at the demuxer boundary so that the
decoder is not handed an attacker-controllable buffer size. Returns
AVERROR_INVALIDDATA on the bound failure with an explicit log line.

Found-by: Claude (Anthropic). Human-verified and reported by
Omkhar Arasaratnam <omkhar@linkedin.com>.
Signed-off-by: Omkhar Arasaratnam <omkhar@linkedin.com>
2026-05-25 21:53:01 +00:00
Zhao Zhili
78a0309735 avformat/movenc: don't overwrite track_duration on every src_track
When a tmcd or similar metadata track references multiple source
tracks, the per-iteration assignment overwrote track->track_duration
on each loop step, leaving it set to whatever the last source happened
to be.
2026-05-25 02:31:09 +00:00
Michael Niedermayer
8f1769703c avformat/mxfdec: zero-init Sony MPEG-4 extradata and add padding
Found-by: Calm (AI security-research agent, for John Bradley / Credex)
2026-05-25 01:34:28 +00:00
Michael Niedermayer
d2d79dca9a avformat/soxdec: Check sample_rate for nan
Found-by: iceray-Li
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-25 01:15:28 +00:00
Michael Niedermayer
c2047918e6 avformat/hls: Check url_offset and size
Fixes: integer overflow

Found-by: jiale yao
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-25 00:10:18 +00:00
Michael Niedermayer
59094859a8 avformat/hls: Check TIME-OFFSET value
Fixes: UB with out of range values
Fixes: poc_overflow.m3u8

Found-by: jiale yao
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-25 00:10:18 +00:00
Zhao Zhili
a0def8f915 avformat/movenc: skip the metadata stream itself when populating tref
A tref stream group lists the metadata stream (e.g. tmcd) alongside the
streams it references. The init loop iterated over every stream in the
group and added it to the metadata track's src_track array, which made
the tmcd track reference itself.

Regression since 4444a755.

Signed-off-by: Zhao Zhili <quinkblack@foxmail.com>
2026-05-24 21:14:31 +00:00
Romain Beauxis
2bae6f9d52 avformat/ogg: drop CELT support 2026-05-23 10:16:38 -05:00
RossWang
bce8d61d12 avformat/libsrt: fix ipv6 wildcard listener
For now it fails on srt://[::]:1234?mode=listener

This modification makes it accept a new option "ipv6only"

Reference:
https://github.com/Haivision/srt/pull/2608
https://github.com/Haivision/srt/blob/master/docs/API/API-socket-options.md#SRTO_IPV6ONLY

fix #10539
2026-05-23 10:03:33 -05:00
Tau Gärtli
8d817a1150
libavformat: Add generic disc_subtitle tag mapping for Vorbis
The mapping is taken from Picard's [1] and taglib's [2] documentation.

The official list [3] of standard field names is pretty short and
does not include one for a disc/part subtitle. Some taggers use
SETSUBTITLE here instead. However, I think DISCSUBTITLE is much more
consistent with the already existing DISCNUMBER field and it matches
what Picard and taglib do.

[1]: https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#disc-subtitle
[2]: https://taglib.org/api/p_propertymapping.html
[3]: https://xiph.org/vorbis/doc/v-comment.html
2026-05-23 16:09:55 +02:00
Tau Gärtli
504c135f8c
libavformat: Add generic disc_subtitle tag mapping for MOV/MP4
The mapping is taken from Picard's [1] and taglib's [2] documentation.

[1]: https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#disc-subtitle
[2]: https://taglib.org/api/p_propertymapping.html
2026-05-23 16:07:57 +02:00
Tau Gärtli
752abe97ab
libavformat: Add generic disc_subtitle tag mapping for ID3v2
The mapping is taken from Picard's [1] and taglib's [2] documentation.

The `TSST` frame is part of ID3v2.4.0:
> The 'Set subtitle' frame is intended for the subtitle of the part
> of a set this track belongs to.

[1]: https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#disc-subtitle
[2]: https://taglib.org/api/p_propertymapping.html
2026-05-23 16:07:50 +02:00
Tau Gärtli
0abe230566
libavformat: Add generic disc_subtitle tag mapping for asf
The mapping is taken from Picard's [1] and taglib's [2] documentation.

The mapping in Microsoft's docs [3] maps `TSST` from ID3 to
`WM/SetSubTitle`. However, some taggers [4] [5] use `WM/SubTitle` instead.
I believe this to be an error, especially since the official docs say otherwise.

[1]: https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#disc-subtitle
[2]: https://taglib.org/api/p_propertymapping.html
[3]: https://learn.microsoft.com/en-gb/windows/win32/wmformat/id3-tag-support
[4]: db95540de6/quodlibet/formats/wma.py (L43)
[5]: 989fb5b8f9/src/plugins/taglibmetadata/taglibasfsupport.cpp (L93)
2026-05-23 16:07:39 +02:00
Tau Gärtli
ac4fc01d6f
libavformat: Add generic disc_subtitle tag 2026-05-23 16:07:21 +02:00
Michael Niedermayer
4492ad7228 avformat/ty: check rec_size
Fixes: ada-4-poc.ty

change is based on the suggested fix

Found-by: Claude and Ada Logics. This issue was found by Anthropic from using agents to study security of open source projects
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-23 00:04:46 +00:00
Zhao Zhili
268c37fdae avformat/iamf_writer: fix stream id log argument
Signed-off-by: Zhao Zhili <quinkblack@foxmail.com>
2026-05-23 02:41:31 +08:00
Dale Curtis
6e0e13b0bf avformat/ogg: Fix overflow and stale oggvorbis_private values
- Prevent integer overflow when summing header lengths; add bounds check.
- Re-initialize priv->vp with the new stream's extradata once all chained
  stream headers are collected.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
2026-05-22 13:27:18 +00:00
Romain Beauxis
cd02463dc6 lavf: wire id3v2 fdebug option
Signed-off-by: Romain Beauxis <romain.beauxis@gmail.com>
2026-05-22 08:20:13 -05:00
Romain Beauxis
274bc5f9ae avformat: deprecate FF_FDEBUG_TS in favor of AV_FDEBUG_TS, add AV_FDEBUG_ID3V2
Signed-off-by: Romain Beauxis <romain.beauxis@gmail.com>
2026-05-22 08:20:13 -05:00
James Almer
b67570b765 avformat/mov_chan: don't share a function that's only used where it's defined
Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-21 18:04:02 -03:00
Franciszek Kalinowski
99e1ecca36 avformat/icecast: reject CR/LF in metadata header values
Reported by Franciszek Kalinowski (isec.pl / striga.ai) and Bartosz Smigielski.
2026-05-21 18:05:39 +00:00
Franciszek Kalinowski
87439ed619 avformat/oggparsecelt: bound extra_headers to avoid an effectively infinite loop
celt_header() reads a uint32 `extra_headers` field from the CELT identification
header and stores `1 + extra_headers` into the signed int extra_headers_left.
With extra_headers = 0x7FFFFFFE this becomes INT_MAX and the OGG parser
consumes every subsequent page as a CELT "extra header" without ever reaching
audio data, hanging on any streaming input. A value of 0xFFFFFFFE wraps the
signed addition negative, with the same family of consequences.

Reject any extra_headers count above a small fixed cap (16, well above any
real CELT-over-Ogg stream).

Verified with the audit PoC (a crafted file plus an infinite-page FIFO):
without the patch, ffmpeg consumes pages forever; with the patch it logs
"Too many CELT extra headers (...)" and exits in ~70 ms with
AVERROR_INVALIDDATA.

Reported by Franciszek Kalinowski (isec.pl / striga.ai) and Bartosz Smigielski.
2026-05-21 14:19:54 +00:00
Franciszek Kalinowski
0857141823 avformat/rtpenc_xiph: bail out when the max payload size underflows
Reported by Franciszek Kalinowski (isec.pl / striga.ai) and Bartosz Smigielski.
2026-05-21 01:15:30 +00:00
Franciszek Kalinowski
a44cae9025 avformat/rtpenc_aac: reject packets smaller than the ADTS header
When extradata_size == 0, ff_rtp_send_aac() does `size -= 7` to skip the
ADTS header without checking size >= 7. A short packet makes size negative,
and the value is later passed to memcpy() as size_t, reading past the buffer
end. Bail out instead.

The vulnerable branch is not reached when using the built-in AAC encoder
(which always emits extradata), but an application that feeds raw
ADTS-stripped AAC packets through the libavformat RTP muxer can hit it. The
fix is a one-line lower-bound check and compiles/runs cleanly; see audit
PoC for the static analysis and reachable-by-API write-up.

Reported by Franciszek Kalinowski (isec.pl / striga.ai) and Bartosz Smigielski.
2026-05-21 01:09:37 +00:00
James Almer
b2ba26a694 avformat/adtsenc: don't accept channeConfiguration values that can't be coded
the ADTS header only has 3 bits for it, so anything higher than 7 can't be
used.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-20 10:59:02 -03:00
Damiano Galassi
1aefacfda4 avformat/movenc: fix mov_create_dvd_sub_decoder_specific_info
It has been broken since 3064487.
2026-05-20 13:53:37 +00:00
Tim Walker
9e71ea2d60 avformat/movenc: write stsd v2 atom when nb_channels > 2
Required by the QuickTime File Format specification.
2026-05-20 12:31:15 +00:00
Tim Walker
6181195d1f avformat/movenc: use sample_rate to determine audio stsd version.
timescale should be equal sample_rate, but the latter is
the actual source field used when writing the stsd atom
since 3b5d4428ac
2026-05-20 12:31:15 +00:00