Commit graph

27320 commits

Author SHA1 Message Date
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
arch1t3cht
e8a4d1ca5c avformat/assdec: Treat negative-duration events as comments
Subtitle events with duration <= 0 may be generated by some authoring
scripts like karoke templates, and are simply treated as hidden by
renderers.

Parsing such subtitle events normally will cause the <= 0 duration to
get mangled by ff_subtitles_queue_finalize() and later
compute_pkt_fields(), causing rendering differences.

Hence, treat such events like comments instead by adding them to the
header so that they are preserved during remuxes, albeit in a different
order.

Signed-off-by: arch1t3cht <arch1t3cht@gmail.com>
2026-05-20 10:10:38 +00:00
Michael Niedermayer
cc1459ed85 avformat/flvdec: Check size at the top of the main loop
Fixes: signed integer overflow
Fixes: ffmpeg_flv_read_packet_libavformat_flvdec.c_1900_26.poc

Found-by: iceray-Li
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-19 23:12:31 +00:00
Michael Niedermayer
84a48165f0 avformat/vividas: fix misaligned access
Fixes: ffmpeg_xor_block_libavformat_vividas.c_134_15.poc

Found-by: iceray-Li
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-19 23:11:33 +00:00
Ramiro Polla
20b009e301 avformat/webp: add Animated WebP demuxer
Original work by Josef Zlomek <josef@pex.com>

Signed-off-by: Ramiro Polla <ramiro.polla@gmail.com>
2026-05-19 11:36:10 +02:00
Michael Niedermayer
2bfc7ce3ec avformat/mccdec: dont pass NULL to bytestream2_put_buffer()
Fixes: passing NULL pointer

Found-by: iceray-Li
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-19 02:33:28 +00:00
Zhao Zhili
b4d11dffbf avformat/rtpdec_av1: fix operator precedence in packet allocation
The closing parenthesis in the av_new_packet() branch was misplaced,
making result store the boolean comparison instead of the AVERROR
code, so allocation failures were silently lost.

av_grow_packet() handles both an empty and a non-empty packet, so use
it for both cases and drop the broken branch.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-05-18 04:00:18 +00:00
James Almer
af739541bf avformat/mov: factorize out tmcd track parsing
Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-17 12:27:59 -03:00
James Almer
4444a75590 avformat/movenc: support writing more than one entry per tref tag
Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-17 11:16:56 -03:00
James Almer
90dd8673ce avformat/mov: handle all references in tref boxes
tref types can have more than one value, as is the case of tmcd in
fcp_export8-236.mov, where the single video track references all timecode
tracks.
Handle them in a generic and extensible way.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-17 11:16:56 -03:00
James Almer
a5822fca94 avformat/avformat: add a Track Reference Stream Group
Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-17 11:16:51 -03:00
James Almer
ef3ff9a73d avformat/iamf_writer: reject unset frame size
The specification states that nb_samples in codec config must not be zero.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-16 13:55:23 -03:00
James Almer
c0bdc3b62a avformat/avformat: add an AVOutputFormat capability flag to signal fixed frame size is needed.
And set it on the IAMF muxer.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-16 13:55:22 -03:00
James Almer
7c5df8d34d avformat/matroskaenc: use frame_size to write audio DefaultDuration
Signed-off-by: James Almer <jamrial@gmail.com>
2026-05-16 13:55:22 -03:00
David Korczynski
08d7646abf avformat/assenc: Add the missing parentheses
Fixes: ada-1-poc.mkv

Found-by: Claude and Ada Logics. This issue was found by Anthropic from using agents to study security of open source projects, and I am from Ada Logics helping validate the found issues and report to maintainers.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-05-16 16:53:51 +00:00
Kacper Michajłow
200cbaeb5a
avformat/hlsenc: use correct close function for custom io
This is open by s->io_open().

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-05-16 18:03:26 +02:00
Kacper Michajłow
06ef9a74ea
avformat/hlsenc: respect io_open set in AVFormatContext
io_open_default() will call internal impl if needed, don't call it
directly.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-05-16 17:18:51 +02:00
Kacper Michajłow
4cf687b3b1
avformat/dashenc: respect io_open set in AVFormatContext
io_open_default() will call internal impl if needed, don't call it
directly.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-05-16 17:18:51 +02:00
Kacper Michajłow
fbc4003642
avformat/dashdec: respect io_open set in AVFormatContext
io_open_default() will call internal impl if needed, don't call it
directly.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-05-16 17:18:51 +02:00
Kacper Michajłow
dc74fe70b2 avformat/demux: use correct close function for custom io
You may look and think `AVFMT_FLAG_CUSTOM_IO` check is enough, but this
is not what it seems. This flag means that user provided custom
AVIOContext, before creating AVFormatContext and it should not be
closed. However nested sub-demuxers may still open an temporary io, and
those have to be closed and use correct io_close2 function.

You can see 0dcac9c3f0 and
ef01061225 where this flag is cleared for
nested opens to avoid leaking those.

lavf micro version bumped so API users can know if it is safe to use
custom io.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-05-16 11:09:56 +00:00
Stuart Eichert
2aad4fb2e3 Typo: Remove space in 'centiseconds', 'microseconds', and 'nanoseconds'.
According to Chapter 3, Paragraph 2 of the "SI Brochure - 9th ed./version 3.02":

> Prefix symbols are printed in upright typeface, as are unit symbols,
> regardless of the typeface used in the surrounding text and are
> attached to unit symbols without a space between the prefix symbol
> and the unit symbol.

https://www.bipm.org/documents/20126/41483022/SI-Brochure-9-EN.pdf
2026-05-15 18:19:40 -07:00
Link Mauve
b5fc215e2d avformat/mods: Return EOF for packets starting at the index offset
Assuming there is no padding between the last packet and the index, this
prevents the index from being parsed as a normal packet, with non-
sensical data.
2026-05-15 19:30:52 +00:00
Link Mauve
c4b7a51d35 avformat/mods: Parse the index entries
This lets us seek in the video properly, based on the table at the end
of the files, and has been tested with Suikoden Tierkreis videos.

While at it I’ve also set the duration of the stream, this makes the
progress bar work correctly in mpv.
2026-05-15 19:30:52 +00:00
Andreas Rheinhardt
b2867481d9 avformat/avformat: Add AVFMT_EXPERIMENTAL to allowed flags
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-05-14 22:58:04 +02:00
Marton Balint
43bbd6dbf9 avformat/utils: avoid void pointer arithmetic
Fixes compliation on MSVC.

Regression since cb708d8703.

Based on code by James Almer.

Signed-off-by: Marton Balint <cus@passwd.hu>
2026-05-14 20:52:45 +02:00
Ben Kepner
a327bc0561 avformat/hlsenc: fix segment duration with mixed stream time bases
When audio and video streams have different time bases (e.g. video at
1/90000 and audio at 1/48000), vs->start_pts was stored as a raw PTS
from whichever stream's packet arrived first. The segment split
comparison then subtracted this value from the current packet's PTS
without accounting for the time base difference, producing incorrect
elapsed time calculations.

This caused segments to be split at wrong points — either too
frequently (on every keyframe) or not at all, depending on the
relative magnitudes of the time bases.

Fix by normalizing vs->start_pts to AV_TIME_BASE_Q at the point of
assignment and converting pkt->pts to the same base before comparison.
This ensures the segment split decision is always unit-consistent
regardless of which stream's packet is being evaluated.

The bug is most easily triggered by HLS muxing with video passthrough
and audio transcode, where the video retains its container time base
while the audio encoder outputs in its native time base.

Signed-off-by: Ben Kepner <u6bkep@gmail.com>
2026-05-13 23:04:46 +00:00
Marton Balint
566ad7869e avformat/hlsenc: remove unused function parameter
Signed-off-by: Marton Balint <cus@passwd.hu>
2026-05-13 22:41:23 +02:00
Marton Balint
f20ea3fb22 avformat/hlsenc: dynamically allocate segment uris along with the segment struct
As suggested by Andreas Rheinhardt.

Supersedes: #22536.

Signed-off-by: Marton Balint <cus@passwd.hu>
2026-05-13 22:41:23 +02:00
Marton Balint
cb708d8703 avformat/utils: add ff_bprint_finalize_as_fam to put bprint strings to flexible array members
Signed-off-by: Marton Balint <cus@passwd.hu>
2026-05-13 22:41:23 +02:00
Kirill Gavrilov
553321d59e libavcodec/hdrdec: accept "#?RGBE" header in addition to "#?RADIANCE"
Some Radiance HDR image files in the wild have "#?RGBE" header,
which other image readers accept.

Also updated hdr_probe() in libavformat/img2dec.
2026-05-13 19:35:33 +00:00
Andreas Rheinhardt
c29d1b9df5 avformat/id3v2: Fix indentation
Forgotten after e9c372362c.

Reviewed-by: Romain Beauxis <toots@rastageeks.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-05-12 16:12:54 +02:00
Andreas Rheinhardt
356e427d5c avformat/id3v2: Use proper logcontext
Otherwise one could not associate log messages with inputs.

Reviewed-by: Romain Beauxis <toots@rastageeks.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-05-12 16:12:51 +02:00
Andreas Rheinhardt
e626b02a01 avformat/id3v2: Avoid temporary buffer
Reviewed-by: Romain Beauxis <toots@rastageeks.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-05-12 16:11:56 +02:00
Marvin Scholz
18761f9fb5 avformat/rtpdec_av1: fix buffer overflow due to variable confusion
The pktpos denotes the position in the output packet buffer, while
buf_ptr is the position in the input buffer. As this payload is ignored,
nothing is written to the output packet so increasing the pktpos does
not make sense here, instead the buf_ptr has to be increased to advance
the input buffer to the correct position after this OBU.

This incorrect increment here could result in pktpos exceeding the whole
size of the output packet and the later call to memcpy to write to that
buffer would start its write way past the end of the packet buffer.

Fix #22812

Reported-By: fre3dm4n
2026-05-12 16:02:51 +02:00
Vignesh Venkat
2c1af16872 avformat/matroskaenc: Use correct buffer for smpte2094_app5
In the call to mkv_write_blockadditional, use the correct
buffer for smpte2094_app5.

Commit 38df985fba updated the
buffer usage to prevent incorrect buffer reuse, but left this line
unchanged inadvertently.

Signed-off-by: Vignesh Venkat <vigneshv@google.com>
2026-05-11 14:44:25 -07:00
Nariman-Sayed
837cf8e38f avformat/tls_mbedtls: fix DTLS handshake failure when receiving non-DTLS packets
Some WebRTC servers such as Pion send STUN packets concurrently during
the DTLS handshake. Unlike OpenSSL and GnuTLS which filter non-DTLS
packets internally, mbedtls passes all received UDP packets directly to
its DTLS state machine, causing the handshake to fail.

Fix this by using ff_is_dtls_packet() in mbedtls_recv to discard
non-DTLS packets such as STUN by returning WANT_READ, as specified
by RFC 5764 Section 5.1.2.

Signed-off-by: Nariman-Sayed <narimansayed28@gmail.com>
2026-05-11 12:36:58 +00:00
Nariman-Sayed
094f72748d avformat/tls: move DTLS packet detection into ff_is_dtls_packet()
Move the DTLS packet detection logic from whip.c into a shared
ff_is_dtls_packet() function in tls.c, with its declaration and
related macros in tls.h. Update whip.c to use the new shared function.

Signed-off-by: Nariman-Sayed <narimansayed28@gmail.com>
2026-05-11 12:36:58 +00:00