Commit graph

125046 commits

Author SHA1 Message Date
Michael Niedermayer
44d082edc8 avfilter/convolution: compute user matrix products in unsigned
Fixes: integer overflow

Found-by: Kery (Qi Kery <qikeyu2001@outlook.com>)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-15 03:15:19 +00:00
Steven Liu
7e1cec8e0a avformat/dashdec: fix unsigned integer overflow in segment number calculation
fix issue: issues/23238
Several time-related fields in DASHContext were declared as uint64_t,
causing the arithmetic in calc_cur_seg_no(), calc_min_seg_no(), and
calc_max_seg_no() to be performed with unsigned semantics.

The expression:
  (get_current_time_in_sec() - availability_start_time) * fragment_timescale
is uint64_t throughout. When presentationTimeOffset is large (e.g. an
absolute epoch-based timestamp common in DVB-DASH live streams), the
subsequent subtraction:
  uint64_t_result - presentation_timeoffset
wraps around to a value near 2^64, because the elapsed wall-clock time
in timescale ticks is far smaller than the absolute presentation time
offset.  The enormous quotient ends up truncated to int32_t when passed
to ff_dash_fill_tmpl_params(), producing a negative $Number$ value in
the segment URL and causing repeated HTTP 403 errors.

Fix this by changing the affected fields and the two helper functions
(get_current_time_in_sec, get_utc_date_time_insec) from uint64_t to
int64_t.  All values involved are well within the int64_t range (Unix
timestamps in seconds and ISO 8601 durations), and the arithmetic
naturally needs signed semantics because intermediate sub-expressions
like (elapsed - time_shift_buffer_depth) can be negative at stream
start.

    Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2026-06-15 02:22:05 +00:00
Michael Niedermayer
f7e6a8ade5 avformat/mpegts: use av_fast_realloc() for prg
Fixes: Timeout
Fixes: 514855073/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTS_fuzzer-5074757044469760
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-15 00:25:34 +00:00
Michael Niedermayer
5f13df1b51 avfilter/avf_showcwt: fix DIRECTION_RL EOF fill clearing the wrong columns
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-14 21:08:21 +00:00
Michael Niedermayer
b276ac07e8 avfilter/avf_showcwt: avoid undefined float to int conversion of nb_consumed_samples
Reproduced with:
ffmpeg -f lavfi -i "sine=frequency=440" -filter_complex \
 "[0:a]showcwt=size=32x32:deviation=0[v]" -map "[v]" -f null -

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-14 21:08:21 +00:00
Michael Niedermayer
d133b4a231 avfilter/avf_showcwt: fix out of array read in compute_kernel
Reproduced with a small output (e.g. size=2x2) under ASan.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-14 21:08:21 +00:00
jiale yao
0d0eadd8ed avfilter/avf_showcwt: fix DIRECTION_DU EOF fill clearing the wrong rows
Fixes: out of array read

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-14 21:08:21 +00:00
Michael Niedermayer
a55a8c9a68 avfilter/v360: compute remap table offsets in 64bit
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-14 21:01:41 +00:00
Michael Niedermayer
fd6b3fa423 avfilter/v360: reject out-of-range dimensions
Fixes: integer overflow

Found-by: Kery (Qi Kery <qikeyu2001@outlook.com>)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-14 21:01:41 +00:00
Andreas Rheinhardt
19e377b4b9 avcodec/x86/hpeldsp: Port mmxext functions to SSE2
The only noticable changes in benchmarks are for
the x2 horizontal no_rnd case where SSE2 and movhps
are beneficial:

Old benchmarks:
avg_pixels_tab[1][1]_c:                                 42.2 ( 1.00x)
avg_pixels_tab[1][1]_mmxext:                            10.8 ( 3.89x)
avg_pixels_tab[1][2]_c:                                 18.0 ( 1.00x)
avg_pixels_tab[1][2]_mmxext:                             6.1 ( 2.96x)
put_no_rnd_pixels_tab[1][1]_c:                          29.7 ( 1.00x)
put_no_rnd_pixels_tab[1][1]_mmxext:                     12.3 ( 2.41x)
put_no_rnd_pixels_tab[1][2]_c:                          20.4 ( 1.00x)
put_no_rnd_pixels_tab[1][2]_mmxext:                     12.2 ( 1.67x)
put_pixels_tab[1][1]_c:                                 29.9 ( 1.00x)
put_pixels_tab[1][1]_mmxext:                             7.6 ( 3.92x)
put_pixels_tab[1][2]_c:                                 16.8 ( 1.00x)
put_pixels_tab[1][2]_mmxext:                             6.4 ( 2.63x)

New benchmarks:
avg_pixels_tab[1][1]_c:                                 42.3 ( 1.00x)
avg_pixels_tab[1][1]_sse2:                              10.7 ( 3.95x)
avg_pixels_tab[1][2]_c:                                 17.8 ( 1.00x)
avg_pixels_tab[1][2]_sse2:                               6.3 ( 2.83x)
put_no_rnd_pixels_tab[1][1]_c:                          29.6 ( 1.00x)
put_no_rnd_pixels_tab[1][1]_sse2:                       10.5 ( 2.81x)
put_no_rnd_pixels_tab[1][2]_c:                          20.4 ( 1.00x)
put_no_rnd_pixels_tab[1][2]_sse2:                       12.3 ( 1.67x)
put_pixels_tab[1][1]_c:                                 30.1 ( 1.00x)
put_pixels_tab[1][1]_sse2:                               7.6 ( 3.93x)
put_pixels_tab[1][2]_c:                                 16.8 ( 1.00x)
put_pixels_tab[1][2]_sse2:                               6.4 ( 2.64x)

Switching to SSE2 unfortunately increased codesize of the relevant
functions by 160B.

This makes these functions ABI compatible, i.e. they no longer
rely on others calling emms_c to fix the fpu state. It also
implies that many mpegvideo decoders (the exceptions are MPEG-4,
RV30, RV40 and the VC-1 family) now no longer use any mmx registers
at all. So one can remove the emms_c from the MPEG-1/2 decoder.
The same is true for VP3.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-14 22:04:42 +02:00
Andreas Rheinhardt
c35f57f3c4 avcodec/x86/fpel: Use SSE2 in avg_pixels8
No change in benchmarks here; this already allows
to remove an emms_c from cavsdec.c.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-14 22:04:42 +02:00
Andreas Rheinhardt
77dbbdcac2 avcodec/x86/hpeldsp: Avoid loading constants
No change in benchmarks here.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-14 22:04:42 +02:00
Andreas Rheinhardt
00ece261b8 avcodec/x86/hpeldsp: Avoid offsetting unnecessarily
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-14 22:04:42 +02:00
Andreas Rheinhardt
0ff6f28437 avcodec/x86/hpeldsp: Deduplicate {avg,put}_pixels{8,16}_y2 macros
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-14 22:04:42 +02:00
Andreas Rheinhardt
65a87545a9 avcodec/x86/hpeldsp: Add _approx to non-bitexact functions' names
Right now, their exact counterparts have a "_exact" in their names;
switch this around.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-14 22:04:42 +02:00
Andreas Rheinhardt
5d277e8c7c avcodec/x86/hpeldsp: Avoid constant in {avg,put}_pixels16_xy2_ssse3
No difference in benchmarks here.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-14 22:04:42 +02:00
Andreas Rheinhardt
f5c26ccf93 avcodec/x86/hpeldsp: Deduplicate {avg,put}_pixels{8,16}_x2 macros
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-14 22:04:42 +02:00
Romain Beauxis
8851de74e8 tests/fate/wav.mak: gate tests that need swresample 2026-06-14 15:03:28 -05:00
Kacper Michajłow
60d868527b
fate/probe: test mpeg-ts with a png prefix and tiff from ticket #5565
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-06-14 21:59:14 +02:00
Kacper Michajłow
0eb2d1f64a
avformat/mpegts: return SCORE_MAX for fully sync-aligned boundary buffers
At check_count == CHECK_COUNT the existing branch caps the score at
SCORE_MAX/2 even when every analyzed packet is sync-aligned and when
analyze() already has full confidence. This loses probe to
signature-only image demuxers (e.g. png_pipe at SCORE_MAX - 1) for
streams with a small leading non-TS prefix. Some CDNs prepend a 1x1 PNG
to MPEG-TS payloads to bypass image-only Content-Type filtering, and the
PNG signature otherwise wins the first probe iteration.

Fixes: https://github.com/mpv-player/mpv/issues/11365

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-06-14 20:51:07 +02:00
Michael Niedermayer
4171581953 swresample/x86/resample: write only int16 in the int16 resampler
The resample asm code as it is currently handles 1 sample at a time

The asm code should be redesigned and handle more than 1 sample at a
time. That is the whole purpose of SIMD. There is also multiple samples
available that need identical handling like from several channels or
similar handling from other points in time.

Such redesign would make the resampler faster and would change the
requirements of padding and maybe memory layout. So it seems simpler
to just avoid overwriting in the asm as it is today than to have
the allocation handle specific overallocation for asm code that
ideally should be redesigned

Fixes writing 16bits over the end of the array

This is an alternative fix for https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23053

Found-by: Ivan Grigorev <ivangrigoriev@meta.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-14 15:34:43 +00:00
Ivan Grigorev
bdbb580d9c swresample/tests: add resample realloc regression test
Add a regression test exercising the swr_convert(N) -> swr_convert(2N)
edge case: the second call reuses the internal preout buffer at full
capacity, with no trailing slack from swri_realloc_audio()'s amortized
doubling. internal_sample_fmt is forced to S16P to reach the int16 SIMD
resample path, where ff_resample_common_int16_sse2 overruns its
destination by 2 bytes on the last iteration.

Without a resampler fix this test fails under valgrind/ASAN with a
heap-buffer-overflow (Invalid write of size 4, 2 bytes past the end).

Signed-off-by: Ivan Grigorev <ivangrigoriev@meta.com>
2026-06-14 15:34:43 +00:00
jiale yao
71478d1165 avformat/rtpenc_amr: Check input size
Fixes: heap buffer overflow

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-14 15:32:48 +00:00
WyattBlue
b1d2190f5f avutil/riscv: Include unistd.h for musl Linux
Before, glibc appears to transitively pull in the syscall number
definitions, but musl does not do this. Thus, `__NR_riscv_hwprobe`
is undeclared and an error is emitted.

Fix this by including `<asm/unistd.h>`, which makes the macro
visible on musl.
2026-06-14 13:51:25 +00:00
Scott Boudreaux
dddc703cc1 swscale/ppc: fix LOAD_FILTER overread in VSX path
Part of the yuv2planeX ASAN fix - replace vec_vsx_ld with vec_splats
to avoid reading past the filter array.

Signed-off-by: Scott Boudreaux <scott@elyanlabs.com>
2026-06-14 13:47:14 +00:00
Scott Boudreaux
d4673a97ac swscale/ppc: fix ASAN stack-buffer-overflow in yuv2planeX
Fix two buffer overreads in the PowerPC yuv2planeX SIMD paths
that cause daily FATE checkasm-sw_scale ASAN failures on both
ppc64 (G5, altivec) and ppc64le (POWER9, VSX):

1. VSX LOAD_FILTER: vec_vsx_ld(joffset, filter) reads 16 bytes
   at the given byte offset.  When joffset >= filterSize*2 - 14
   (e.g. joffset=30 for filterSize=16), this reads up to 14 bytes
   past the 32-byte filter array.  Fix by replacing the vector
   load with vec_splats(f[j]) which only reads the single int16_t
   element needed (the result is splatted to all lanes anyway).

2. GET_LS look-ahead overread: yuv2planeX_8_16 calls
   yuv2planeX_8 twice per filter tap.  Each call's GET_LS macro
   speculatively loads the next 16-byte vector for pipelining.
   On the second call, this look-ahead reads 16 bytes past the
   last valid source element.  Fix by tightening the SIMD loop
   bound from (dstW - 15) to (dstW - 23), ensuring the farthest
   speculative load stays within src[j][0..dstW-1].  The scalar
   fallback handles the remaining 16-23 trailing pixels.

The ASAN reports from FATE:
  ppc64 (altivec): stack-buffer-overflow in yuv2planeX_8_16_altivec
                   at swscale_ppc_template.c:56
  ppc64le (VSX):   unknown-crash in yuv2planeX_8_16_vsx
                   at swscale_ppc_template.c:52

Signed-off-by: Scott Boudreaux <scott@elyanlabs.com>
2026-06-14 13:47:14 +00:00
Niklas Haas
6698195dc4 avformat/shared: propagate correct short seek size on failure
This might be AVERROR(ENOSYS), which we shouldn't propagate.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
Niklas Haas
fa6a5807c2 avformat/shared: allow AVERROR_EXIT/EAGAIN as transient failures
These shouldn't really permanently invalidate the block.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
Niklas Haas
f87923765d avformat/shared: robustness fix for seek-past-end
If the filesize is known as a result of AVERROR_EOF on a block that ends
before the current seek position, this might end up negative. Error
out cleanly instead of aborting.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
Niklas Haas
a22037858e avformat/shared: use flock() instead of fcntl()
flock() also locks against accesses by other threads of the same
process, unlike fcntl().

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
Niklas Haas
9140cbe583 avformat/shared: don't read directly into cache file when racing writes
Instead, read to the output/temporary buffer (write_back path). This is to
lessen the impact of racing the write against other clients trying to race
the same pending block.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
Niklas Haas
58e5ec8a5a avformat/shared: allocate fallback buffer unconditionally
Needed for the upcoming commit, but also more robust in general. The memory
waste is negligible.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
Niklas Haas
c97a2328c0 avformat/shared: set default cache timeout to 10 ms
This value is matched to the typical seek latency in a reasonably capable
7200 rpm disk device, as well as the typical latency of an on-premise HTTP
request.

Note that this change should rarely have a significant effect, because
it only matters when using multiple concurrent processes, and one process
is somehow stuck in I/O (or died). Since we sleep in a loop for 1/16th of
the requested timeout value, this should only increase the effective read
latency by up to ~500 us on top of the actual underlying latency.

The alternative is hammering the same underlying resource with the exact
same requests at the exact same time (e.g. during init).

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
Niklas Haas
5dd020faff avformat/shared: error out if filesize does not match expected
If this happens, something is almost surely wrong with the cache file
(e.g. mismatched source file), so it's much better to error out rather than
hit silent data corruption.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
Niklas Haas
a37c00c4e9 avformat/shared: add missing ret = 0
Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
deng.zewen
f704dd77b7 libavcodec/riscv: add RVV optimized hevc_add_res 2026-06-14 03:10:29 +00:00
James Almer
e772f50a65 fftools/ffmpeg_demux: ensure tile grid stream groups are sane
This is already checked in libavformat, at least in the only demuxer that
creates them, but best not risk an out-of-bounds access in case a new demuxer
doesn't take the proper measures.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-06-13 21:52:32 -03:00
James Almer
3d2c02f1dd avcodec/bsf/h264_mp4toannexb: don't overwrite output codecpar extradata after init()
It's against the documented behavior of bitstream filters.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-06-13 21:32:07 -03:00
Michael Niedermayer
ab5043f055 avcodec/sanm: reject codec37 frames taller than the allocated buffer
No testcase

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-13 22:03:59 +00:00
Michael Niedermayer
b2695bcbb3 avcodec/sanm: reject codec47 frames taller than the allocated buffer
Fixes: 513469519/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SANM_fuzzer-5024854725427200
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-13 22:03:59 +00:00
Michael Niedermayer
f7368f97b9 avfilter: use ff_slice_pos() for per-slice boundary computation
This is a behavior preserving change for all non-overflowing cases.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-13 21:41:05 +00:00
Michael Niedermayer
218b4771a3 avfilter: add ff_slice_pos() helper for slice boundaries
Slice based filter workers compute their per-thread row/sample/channel
boundaries as total * jobnr / nb_jobs. The total * jobnr product is
evaluated in int and overflows signed int for large dimensions and many
slice threads, before the division by nb_jobs brings it back in range.
2026-06-13 21:41:05 +00:00
Michael Niedermayer
200e0cba67 avfilter/estdif: avoid signed overflow in slice boundary calculation
deinterlace_slice() computed per-thread row boundaries with int
multiplication height * (jobnr + 1). With a tall frame and many filter
threads the product overflows signed int before the division by nb_jobs.

Use int64_t for the intermediate product before converting back to int
row indices.

Found-by: Kery (Qi Kery <qikeyu2001@outlook.com>)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-13 21:41:05 +00:00
Michael Niedermayer
2ff28aca4b avcodec/jpeglsdec: bound cumulative decoded JPEG-LS height per packet
Fixes: Timeout
Fixes: 509211998/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_THP_fuzzer-5098892286033920
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-13 21:40:40 +00:00
Michael Niedermayer
10f2abc41f swscale: support sliced input with cascaded scaling contexts
Previously scale_cascaded() assumed the whole source frame arrived in a
single sws_scale() call, and the dispatcher only routed full-frame calls
to it. A partial input slice fell through to ff_swscale() on the parent
dispatcher context, whose scaler state (c->desc) is never initialized in
cascade mode, causing a NULL dereference / crash.

Top-down sliced output is bit-exact with full-frame scaling; bottom-up
matches swscale's pre-existing (non-cascade) slice behaviour for
subsampled intermediate formats.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-13 21:32:37 +00:00
Michael Niedermayer
6049b4d7bc avformat/rtspdec: bound Content-Length in the ANNOUNCE handler to SDP_MAX_SIZE
Reported by Franciszek Kalinowski (isec.pl / striga.ai) and Bartosz Smigielski.
2026-06-13 21:31:18 +00:00
James Almer
0cf9169c85 avcodec/cbs_h266_syntax_template: reject subpic info with res_change_in_clvs
Found-by: Anthony Hurtado
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-13 15:57:19 +00:00
Michael Niedermayer
7b717fe50d avcodec/misc4: Check nb channels
Found-by: Forgejo Fairy
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-13 15:55:40 +00:00
Michael Niedermayer
0c662529f6 avcodec/rv10, rv34: check init_get_bits8() before RealVideo bit access
Found-by: Samarth Kumbla <samarthk@cantina.security>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-13 15:54:44 +00:00
Ling, Edison
3773831c21 avcodec/d3d12va_encode: Add H264/HEVC constrained intra prediction parameter support
Add parameter `constrained_intra_pred` for users to enable constrained intra prediction (as opposed to default unconstrained) in D3D12 H264 and HEVC encoding.

Usage:
  false (default): `-constrained_intra_pred false`  or  `-constrained_intra_pred 0`
  true:            `-constrained_intra_pred true`   or  `-constrained_intra_pred 1`

Sample command line:
```
ffmpeg.exe -hwaccel d3d12va -hwaccel_output_format d3d12 -i input.mp4 -c:v h264_d3d12va -constrained_intra_pred true -y output.mp4
ffmpeg.exe -hwaccel d3d12va -hwaccel_output_format d3d12 -i input.mp4 -c:v hevc_d3d12va -constrained_intra_pred true -y output.mp4
```
2026-06-13 11:21:14 +00:00