Commit graph

26880 commits

Author SHA1 Message Date
Ruikai Peng
bb424927db avformat/sierravmd: fix header read error check
The header read check stored the comparison result into ret, so read
failures became ret=1 and were treated as success, leaving the VMD header
uninitialized and letting parsing continue with bogus state.

Regression since: ee623a43e3.
Found-by: Pwno
2025-12-11 16:26:17 +00:00
James Almer
16050a1cef avformat/iamf_writer: ensure expanded_loudspeaker_layout is only written when using a single scalable layout layer
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-09 17:54:11 -03:00
James Almer
5cdc1cad77 avformat/iamf_parse: add a few extra sanity checks
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-09 17:54:11 -03:00
James Almer
2d5abf27e5 avformat/iamf_parse: fix parsing of Scalable layouts with Mono and Stereo layers
An ASAN heap-buffer-overflow in scalable_channel_layout_config was caused by an
unchecked assumption that the channel layout of a scalable audio layer is a
superset of the previous layer's channel layout.

scalable_channel_layout_config constructs a channel layout map by copying
channels from the previous layer and adding new ones. The memory allocation is
based on the target loudspeaker_layout. However, if the target layout doesn't
encompass all previous channels (e.g., Mono to Stereo), copying previous
channels followed by adding current ones could exceed the allocated size,
causing a heap buffer overflow.

This commit adds an exception for the know case of Mono -> Stereo, and a check
to ensure the previous layer's channel layout is a subset of the current
layer's layout by comparing their masks. If the condition isn't met,
an error is returned.

Fixes: https://issues.oss-fuzz.com/issues/464965414

Co-authored-by: Oliver Chang <ochang@google.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-09 17:54:11 -03:00
James Almer
ac9552bebf avformat/cbs: add missing license headers
Signed-off-by: James Almer <jamrial@gmail.com>
2025-12-08 20:07:45 -03:00
caifan3
40d7f7774a avformat/unix: add pkt_size option
Add a "pkt_size" AVOption to the Unix domain socket protocol. This option
allows the user to specify the maximum packet size for packet-oriented
sockets (SOCK_DGRAM and SOCK_SEQPACKET).

Signed-off-by: caifan3 <caifan3@xiaomi.com>
2025-12-07 19:36:03 +00:00
Andreas Rheinhardt
e0845ec2cf avformat/movenc: Fix leak of IAMFContext on error
Forgotten in 5b87869c09.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-04 16:15:09 +00:00
Michael Niedermayer
12e7d095b1 Revert "avformat/rawdec: set framerate in codec parameters"
Fixes single image videos
this works and creates our single image video
./ffmpeg -i lena.pnm /tmp/file.m2v

this fails after 3d96d83a0a:
./ffmpeg -i /tmp/file.m2v /tmp/file.jpg -y

This reverts commit 3d96d83a0a.
2025-12-04 01:59:04 +00:00
wutno
f4312ea138 avformat/xmv: Handle zero sized packet at end of file
Some XMVs introduce a blank packet at the end of the stream. Previously, we
didn't account for this and returned AVERROR_INVALIDDATA, indicating an issue
with the file. Instead, let's check for this and close out with AVERROR_EOF.
2025-12-03 22:09:20 +00:00
Andreas Rheinhardt
5d9270df7f libavutil/internal: Remove {SIZE,PTRDIFF}_SPECIFIER
Possible since 222127418b.

Reviewed-by: Kacper Michajłow <kasper93@gmail.com>
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-12-03 11:52:54 +01:00
Gavin Li
3d96d83a0a avformat/rawdec: set framerate in codec parameters
Commit ba4b73c977 caused a regression in
the usage of avg_frame_rate to detect the frame rate of raw h264/hevc
bitstreams: after the commit, avg_frame_rate is always the value of the
-framerate option (which is set to 25 by default) instead of the actual
frame rate derived from the bitstream SPS/VPS NALUs.

This commit fixes the regression by setting the framerate codec
parameter to the value of the framerate option instead. After this
change, bitstreams without timing information will derive avg_frame_rate
from the -framerate option, while bitstreams with timing information
will derive avg_frame_rate from the bitstream itself.

The h264-bsf-dts2pts test now returns the correct frame durations for a
bitstream with a mix of single-field and double-field frames.

Signed-off-by: Gavin Li <git@thegavinli.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-27 20:01:54 -03:00
Anthony Bajoua
93ccca22bb libavformat/mov: Fixes individual track duration on fragmented files 2025-11-27 14:05:33 +00:00
Zhao Zhili
cac5018eb9 avformat/mov: fix crash when stsz_sample_size is zero and sample_sizes is null
Co-Authored-by: James Almer <jamrial@gmail.com>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-11-27 14:03:06 +00:00
James Almer
faa382e5b1 avformat/iamf_parse: ensure the stream count in a scalable channel representation is equal to the audio element's stream count
Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-26 12:01:17 -03:00
James Almer
554ae5ada9 avformat/iamf_parse: ensure each layout in an scalable channel representation has an increasing number of channels
Fixes issue #21013

Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-26 12:01:17 -03:00
Andreas Rheinhardt
2a90e7d725 av{codec,util}/tests: Remove pointless undefs
Before commit e96d90eed6 lavu/internal.h
contained redefined various discouraged/forbidden functions to induce
compilation failures upon use, like e.g.
 #define malloc please_use_av_malloc
In order to use these functions, some files had to undefine these
macros. This commit removes the remaining pointless undefs.

Reviewed-by: Rémi Denis-Courmont <remi@remlab.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-11-24 16:48:31 +01:00
James Almer
ee623a43e3 avformat: don't return EIO on demuxer errors
Demuxers should not generate this error code when they encounter truncated
or otherwise invalid files. It's a code the underlying protocol should generate
when there are legitimate reading errors.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-24 12:07:15 -03:00
James Almer
6f4a3be9dc avformat/movenc: add support for writing srat box
Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-24 02:59:02 +00:00
James Almer
fd4e86be9e avformat/mov: reindent after the previous change
Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-23 17:01:39 -03:00
Zhao Zhili
d3e80837e7 avformat/mov: fix incorrect sample rate by parse srat box 2025-11-23 12:13:07 +00:00
James Almer
c0044ec9c4 avformat/mov: don't parse reserved ISOBMFF fields as if they were QT
Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-23 11:51:26 +00:00
Andreas Rheinhardt
775b102182 avformat/oggenc: Schedule pagesize option for removal
Deprecated in 59220d559b.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-11-21 18:41:15 +00:00
Hendi
b399896046 avformat/dashdec: Fix urls with special characters in manifest
This was especially a problem with ampersands, which occur
frequently as part of query parameters.
2025-11-18 22:10:34 +00:00
Artem Smorodin
e94439e49b avformat/tee: fix the default onfail setting of the tee salves
I found that the default value is not set for onfail option. I see that there is an attempt to set this value by default inside parse_slave_failure_policy_option. But look at the CONSUME_OPTION macro. If av_dict_get cannot find this option, then this function is not even called.
2025-11-17 00:01:42 +00:00
James Almer
6cdd2cbe32 avformat/riffenc: add support for HEAACWAVEFORMAT
This is an extension to WAVEFORMATEX used for some AAC streams, defined in the
Windows SDK.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-12 21:30:02 -03:00
James Almer
362d673ad6 avformat/riffdec: add support for HEAACWAVEFORMAT
This is an extension to WAVEFORMATEX used for some AAC streams, defined in the
Windows SDK.

Fixes issue #20887.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-11-12 21:29:49 -03:00
Martin Storsjö
032bdf8ebd Revert "Re-initialize stream on new metadata."
This reverts commit 7b18eafabd.

That commit added tests that don't work on Windows, and which
also fail in setups with cross/remote testing (with --target-exec
and --target-path).

See https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20876 for more
discussions about issues with that commit.
2025-11-10 14:03:43 +02:00
Michael Niedermayer
c199b3d48f avformat/whip: Fix rtp_ctx->streams access
Fixes: out of array access
No testcase

Found-by: Joshua Rogers <joshua@joshua.hu> with ZeroPath
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-11-10 00:24:44 +00:00
Romain Beauxis
7b18eafabd Re-initialize stream on new metadata. 2025-11-09 11:45:37 -06:00
Andreas Rheinhardt
dd05022def avformat/mp3enc: Avoid av_unused
Possible now that -Wdeclaration-after-statement is no more.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-11-09 13:44:18 +01:00
Romain Beauxis
f2b9b1923d Don't reset last{pts,dts} on new sequentialized ogg streams.
This fixes PTS/DTS discontinuity on sequentialized ogg streams.
2025-11-09 10:46:08 +00:00
Martin Storsjö
586898dc1f avformat: Make ff_make_codec_str output to an AVBPrint object 2025-11-08 21:19:31 +00:00
Martin Storsjö
900b77b1b7 hlsenc, dashenc: Share the routine for generating a codec string
The one in dashenc was added in
fe5e6e34c0, while the one in hlsenc
was added later in 0afa171f25. Both
have had various additions on top; merge both implementations
into one shared. (Notable additions in
060e74e2a9,
1cf2f040e3,
a2b1dd0ce3 and
797f0b27c1.)

For H264/avc1, use the implementation from hlsenc (which doesn't
use temporary allocations). For most other codecs, use the
only implementation from whichever had one.

The original dashenc implementation tried to be generic based
on RFC 6381, looking up codec tags in ff_codec_movvideo_tags
or ff_codec_movaudio_tags, and doing specific extra additions
for "mp4a" and "mp4v". In practice, only AV_CODEC_ID_AAC
and AV_CODEC_ID_MPEG4 ever mapped to these; simplify this to
a more straightforward codec id based handling, and merge
with the AAC profile based code from hlsenc.

There's a slight behaviour difference from the old one in
dashenc; if there's no code for a specific codec ID, we previously
just output what we matched from the mov tag tables, but now
we won't output anything. But most commonly used codecs in
DASH should be covered here.
2025-11-08 21:19:31 +00:00
Martin Storsjö
ee22107c67 avformat/vpcc: Make input pointers const 2025-11-08 21:19:31 +00:00
Martin Storsjö
d015382f4a avformat/vpcc: Generalize the AVFormatContext parameter to void*
This parameter is only used as a logging context; don't require
a full AVFormatContext here.
2025-11-08 21:19:31 +00:00
Michael Niedermayer
d4e0d5ed48
avformat/rtpdec_rfc4175: Check dimensions
Fixes: out of array access
Fixes: zeropath/int_overflow_in_rtpdec_rfc4175

Found-by: Joshua Rogers <joshua@joshua.hu>
Reviewed-by: Joshua Rogers <joshua@joshua.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-11-08 18:41:24 +01:00
Michael Niedermayer
c03e49dd1d
avformat/rtpdec_rfc4175: Only change PayloadContext on success
Reviewed-by: Joshua Rogers <joshua@joshua.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-11-08 18:41:24 +01:00
Michael Niedermayer
af3dee3132
avformat/rtpdec_rfc4175: Fix memleak of sampling
Reviewed-by: Joshua Rogers <joshua@joshua.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-11-08 18:41:17 +01:00
Michael Niedermayer
b518c027a0
avformat/http: Fix off by 1 error
Fixes: out of array access
Fixes: zeropath/off-by-one-one-byte

Found-by: Joshua Rogers <joshua@joshua.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-11-08 02:26:36 +01:00
Zhao Zhili
632958d2bf avformat/mov: log unknown tag via av_fourcc2str
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-11-05 23:45:31 +08:00
Zhao Zhili
07581d6736 avformat/mov: check prji box version and flags
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-11-05 23:45:31 +08:00
Zhao Zhili
0734d1c55a avformat/mov: relax check on proj box size
Pico VR adds a '\0' after projection_type (a real C string than
a fourcc). It's not strictly correct, but doesn't affect parsing.

[prji: Projection Information Box]
    position = 149574743
    size = 17
    version = 0
    flags = 0x000000
    projection_type = rect

Co-Authored-by: Keven Ma
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-11-05 23:45:31 +08:00
Martin Storsjö
8313dc1120 movenc: Make hybrid_fragmented retain the fragmented form headers
This makes the final file truly hybrid: Externally the file
is a regular, non-fragmented file, but internally, the fragmented
form also exists un-overwritten.

To make any use of that, first, the fragments need to be muxed in
a position independent form, i.e. with empty_moov+default_base_moof
(or the dash or cmaf meta-flags).

Making use of the fragmented form when the file is finalized is
not entirely obvious though. One can dump the contents of the
single mdat box, and get the fragmented form. (This is a neat
trick, but not something that anybody really is expected to
want to do.)

The main expected use case is accessing fragments in the form of
byte range segments, for e.g. HLS.

Previously, the start of the file would look like this:

- ftyp
- free
- moov
 - (moov contents)

After finalizing the file, it would look like this:

- ftyp
- free
- mdat (previously moov)
 - (moov contents)

In this form, the size and type of the original moov box were
overwritten, and the original moov contents is just leftover
as unused data in the mdat box.

To avoid this issue, the start of the file now looks like this:

- ftyp
- free
- free
 - ftyp
- moov
 - (moov contents)

The second, hidden ftyp box inside mdat, would normally never be
seen.

After finalizing, the difference is that the mdat box now is
extended to cover the ftyp and the whole moov including its header
(and all the following fragments).

I.e., the start of the file looks like this:

- ftyp
- free
- mdat
 - ftyp
 - moov
  - (moov contents)

This allows accessing the "ftyp+moov" pair sequentially as such,
with a byte range - this range is untouched when finalizing,
producing the same ftyp+moov pair both while writing, when the
file is fragmented, and after finalizing, when the file is
transformed to non-fragmented externally.

Note; the sequential two "free+free" boxes may look slightly
silly; it could be tempting to make the second one an mdat
from the get-go. However, some players of fragmented mp4 (in
particular, Apple's HLS player) bail out if the initialization
segment contains an mdat box - therefore, use a free box.

It could also be possible to use just one single free box with
8 bytes of padding at the start - but that would require more
changes to the finalization logic.

For a segmenting user of the muxer, the only unclarity is how
to determine the right byte range for the internal ftyp+moov
pair. Currently, this requires parsing the muxer output and skip
past anything up to the start of the non-empty free box.
2025-11-04 10:23:31 +00:00
Michael Niedermayer
5b98cea4bf
avformat/sctp: Check size in sctp_write()
Fixes: out of array access
No testcase

Found-by: Joshua Rogers <joshua@joshua.hu> with ZeroPath
Reviewed-by: Joshua Rogers <joshua@joshua.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-11-01 23:22:32 +01:00
Michael Niedermayer
83e0298de2
avformat/rtmpproto: consider command line argument lengths
Fixes: out of array access
Fixes: zeropath/rtmp-2025-10

Found-by: Joshua Rogers <joshua@joshua.hu>
Reviewed-by: Joshua Rogers <joshua@joshua.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-11-01 19:54:07 +01:00
Michael Niedermayer
a64e037429
avformat/rtmpproto_ Check tcurl and flashver length
Fixes: out of array accesses

Reviewed-by: Joshua Rogers <joshua@joshua.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-11-01 19:53:46 +01:00
lholliger
e59d964a3c libavformat/mov: add support for name udta
In the QTFF documentation for udta/"user data atoms", "name" is a
valid entry for "name of object" however it is currently skipped
leading to some missing metadata when copying for some files. This
isn't classified the same as "(C)nam" which is "Title of content"
so they aren't necessarily the same.
2025-10-31 14:28:23 +00:00
Desmond Liu
4348bde2d2 libavformat/udp: Fix call to recvfrom(2)
Last parameter to recvfrom() is not initialized, causing
recvfrom() to randomly return EINVAL. Issue was introduced in
af04a27893.
2025-10-30 17:22:12 -07:00
Michael Niedermayer
d03483bd26
avformat/rtpenc_h264_hevc: Check space for nal_length_size in ff_rtp_send_h264_hevc()
Fixes: memcpy with negative size
Fixes: momo_trip-poc/input

Reported-by: Momoko Shiraishi <shiraishi@os.is.s.u-tokyo.ac.jp>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-10-30 01:24:23 +01:00
Baptiste Coudurier
1025beeef1 lavf/id3v2: allow empty strings without bom, fixes #20597 2025-10-28 10:59:25 -07:00