1
0
mirror of https://git.ffmpeg.org/ffmpeg.git synced 2026-10-24 02:09:03 +03:00

123824 Commits

Author SHA1 Message Date
Timo Rothenpieler
1041abdc96 avformat/tls_gnutls: actually send client cert if one is provided
Without setting this flag, apparently gnutls will only send the client
certificate according some logic based on what it thinks the server
accepts.
This is not the case a lot of times.
Just force it to send the client cert the user supplied, if one was
supplied, no matter what.

Fixes #22707

(cherry picked from commit 5c35d0b880)
n8.1.3
2026-09-20 23:13:50 +00:00
James Almer
b2f422d306 avcodec/libfdk-aacdec: clear and reset some fields when flushing
The decoder can't know where a seek landed, so the "delay_samples" way to
discard the decoder delay in the first frame is not truly viable, so it needs
to be removed.
Add a call to aacDecoder_DecodeFrame() with the AACDEC_CLRHIST flag set, as the
call to aacDecoder_SetParam() with the AAC_TPDEC_CLEAR_BUFFER setting was
seemingly not enough to truly flush all the fdkaac internal buffers.

Should fix issue #24527.

Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit b894a6f7c1)
2026-09-19 22:26:38 -03:00
James Almer
ec8ec90d51 avcodec/libfdk-aacdec: properly handle decoder delay
Shift timestamps when available, and take into account the caller requested
samples to be discarded alongside the decoder delay.

Should fix issue #24526.

Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit c8595be8e6)
2026-09-19 22:26:38 -03:00
James Almer
07cf17663e Changelog: fix typos in a couple entries
Makes the Lint CI job happy.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-09-19 21:35:05 -03:00
James Almer
a8e6b8cba7 avcodec/libfdk-aacdec: fix the check for downmix layout order
The code reads a mask afer this check, meaning it expects NATIVE order, not
others.

Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit 7755d264bd)
2026-09-19 21:08:26 -03:00
Michael Niedermayer
a4a6cb1e4a Bump for 8.1.3 2026-09-19 18:28:12 +02:00
Michael Niedermayer
ad096ddd65 cosmetics: Changelog: drop the commit hashes from the 8.1.3 entries
The 8.1.3 section listed every entry with its commit hash and one
entry also named a private branch. The entries now use the same
format as the 8.1.2 section, only the pull request references stay.
2026-09-19 18:28:05 +02:00
Michael Niedermayer
b2957392d5 Changelog: update for the fixes since 8.1.3 2026-09-19 18:05:15 +02:00
Kacper Michajłow
4bca65da83 Revert "lavfi/bwdif: fix heap-buffer-overflow with small height videos"
This reverts commit 5bc4a9898c.

The heap-buffer-overflow was a symptom of the >8 bit boundary
conditions bug fixed in the previous commit. This workaround is no
longer needed.

This restores spatial-only interpolation of the whole frame for the
first and last fields, instead of running the temporal edge filter
against cloned reference frames on the outermost lines. Because of that
first frame references are updated to pre-fix values.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
(cherry picked from commit 3cd408c2a6e5a7de8b6d641dedd12d523b94014c)
2026-09-19 17:01:18 +02:00
Kacper Michajłow
11076bf269 avfilter/vf_bwdif: fix line boundary checks for >8 bits content
The mrefs/prefs boundary conditions scaled the y limits by the number of
bytes per sample, even though the ref offsets are already expressed in
elements. For content deeper than 8 bits this clamped perfectly valid
in-bounds line taps.

Found by validating the libplacebo GPU port against this filter, which
matches exactly on 16-bit content everywhere except these lines.

This changes the output for >8 bit content on the affected lines.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
(cherry picked from commit 7d96c87a7382fed8d571748d6ed5c1869c192c31)
2026-09-19 17:00:37 +02:00
Jack Lau
6442b04b0f avformat/hlsenc: fix compile error when mp4 is disabled
Regression since dc4c798970

Handle the case where mp4 is disabled since mp4 as
an optional dependency of hls_muxer.

Signed-off-by: Jack Lau <jacklau1222gm@gmail.com>
(cherry picked from commit 0510aff11b)
2026-09-19 17:00:37 +02:00
Ramiro Polla
b46c21cf03 swscale/unscaled: fix rgbToRgbWrapper for non-native-endian formats
The fix from 5fa2a65c11 introduced a regression for non-native-endian
formats (such as rgb565be on a little-endian system).

Reproducible with:
$ ./libswscale/tests/swscale -unscaled 1 -src rgb565be -dst rgb24

Also:
$ ./ffmpeg_g -i /opt/samples/jpegls/128.jls -vf "scale=size=512x512,format=rgb24,scale=flags=neighbor,format=rgb565be" -f rawvideo -vframes 1 -y rgb565be.raw
$ magick -size 512x512 -endian MSB RGB565:rgb565be.raw output.png
$ ./ffplay_g output.png

(note: don't use ffmpeg to convert from rgb565be.raw to output for the
test above since it will perform the same bug and cancel out the error)

(cherry picked from commit d0a84c660a)
2026-09-19 17:00:37 +02:00
Kacper Michajłow
51715a5344 avformat/hls: avoid casting callback functions type
Technically it's is UB to call function of different type.

Fixes:
src/libavformat/utils.c:531:9: runtime error: call to function handle_variant_args through pointer to incorrect function type 'void (*)(void *, const char *, int, char **, int *)'
src/libavformat/hls.c:379: note: handle_variant_args defined here

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
(cherry picked from commit d768bd564e)
2026-09-19 17:00:29 +02:00
Michael Niedermayer
a1ced74e8d avcodec/vulkan/ffv1_dec_setup: act on the slice header rejection
(cherry picked from commit 533a3c254d)
2026-09-19 17:00:18 +02:00
Michael Niedermayer
b2c3ad438c avformat/hlsenc: reject out-of-range EXT-X-PROGRAM-DATE-TIME
Parse the timestamp with av_small_strptime() instead of sscanf(): it
range-checks each field (year 0-9999, month, day, hour, minute, second)
and limits the number of digits consumed, so an oversized field can no
longer overflow during parsing. The mktime() result is additionally
checked for EOVERFLOW.

Fixes: integer overflow

Found-by: Kery (Qi Kery <qikeyu2001@outlook.com>)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit c82196b299)
2026-09-19 17:00:07 +02:00
Niklas Haas
4d58e9d8d4 avformat/http: only re-use old connection if valid
Otherwise, this might leak stale bytes that were already drained by the
HTTP soft-seek attempt.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
(cherry picked from commit 0d0f9a06ab)
2026-09-19 16:59:28 +02:00
Niklas Haas
cb4c0da19c avformat/http: properly re-set s->range_end before requests
Otherwise this could leak stale values from a previous response.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
(cherry picked from commit 8712114200)
2026-09-19 16:59:28 +02:00
Niklas Haas
9b88ec3141 avutil/rational: avoid signed integer overflow
Passing -INT_MIN to av_sub_q() overflows due to the negation. Writing out
the formula explicitly avoids this.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
(cherry picked from commit 6a853ce327)
2026-09-19 16:59:28 +02:00
Michael Niedermayer
6cebacddcc avformat/mpegts: Fix memleak of pes_filter.opaque
Fixes: 490257166/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTS_fuzzer-4815675538604032

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit c25673fe70)
2026-09-19 16:59:28 +02:00
Michael Niedermayer
3cd473d862 avcodec/leaddec: Check input data before allocating buffer
Fixes: Timeout
Fixes: 471636089/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LEAD_fuzzer-6346348464242688

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit a780d46d3b)
2026-09-19 16:59:28 +02:00
Michael Niedermayer
959b0d1563 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>
(cherry picked from commit 2ff28aca4b)
2026-09-19 16:59:28 +02:00
Michael Niedermayer
e1d767484b avcodec/cbs_h265: allocate VPS hrd_parameters dynamically
H265RawVPS embedded hrd_parameters as an inline array of
HEVC_MAX_LAYER_SETS (1024) H265RawHRDParameters, making the structure
roughly 7.9 MB. CBS allocates the whole content structure for every VPS
NAL unit before parsing it, so a packet consisting of many tiny VPS NALs
forces gigabytes of allocations and triggers an out-of-memory condition.

Allocate hrd_parameters separately, sized to vps_num_hrd_parameters,
backed by an AVBufferRef registered as a second internal reference
offset on the VPS unit type. This shrinks the resident structure to tens
of kilobytes and bounds the hrd_parameters allocation by the amount that
is actually parsed.

Fixes: 472754452/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-6379024978083840
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit d2dd0a0a8f)
2026-09-19 16:59:28 +02:00
Andreas Rheinhardt
2bd4a58d87 avcodec/atsc_a53: Avoid GetBits API to parse A53 CC data
This fixes overreads with libdav1d, because it provides
non-padded data in violation to the requirements of
the GetBits API.

Furthermore, using the GetBits API here is wasteful,
as the offsets here are known and the actual data to be copied
is even byte-aligned, allowing to use memcpy.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit f2e5eff3ff)
2026-09-19 16:59:28 +02:00
Franciszek Kalinowski
32433b4b56 avcodec/pngdec: bound decompressed zTXt/iCCP size (decompression-bomb guard)
decode_zbuf() inflates zTXt (compressed text) and iCCP (ICC profile) chunk
payloads into an AVBPrint created with AV_BPRINT_SIZE_UNLIMITED and never
checks the decompressed size. A ~100 KB zTXt chunk of compressed zeros
expands to 100 MB; larger ratios or multiple chunks can exhaust memory.

Abort with AVERROR_INVALIDDATA once the decompressed output crosses a hard
cap (16 MiB).

Verified with a crafted PNG (1 KB compressed -> 100 MB decompressed): without
the patch the chunk fully decompresses, taking >100 MB; with the patch the
inflate loop aborts and the decoder logs "Compressed PNG chunk expands
beyond 16777216 bytes" / "Broken zTXt chunk" while the rest of the image
decodes normally.

Reported by Franciszek Kalinowski (isec.pl / striga.ai) and Bartosz Smigielski.

(cherry picked from commit 69bdb05f36)
2026-09-19 16:59:28 +02:00
Linke
678672a786 avformat/av1: fix uvlc loop past end of bitstream
When get_bits_left() returns a negative value (bitstream reader already past the end of the buffer), the while condition while (get_bits_left(gb)) evaluates to true since any non-zero int is truthy.

With the safe bitstream reader enabled, get_bits1() returns 0 past the buffer end, so the break never triggers and leading_zeros increments toward INT_MAX.

Change the condition to > 0, consistent with skip_1stop_8data_bits() which already uses <= 0 for the same pattern.

Signed-off-by: Linke <1102336121@qq.com>
(cherry picked from commit e44d76f61f)
2026-09-19 16:59:28 +02:00
James Almer
8f0166f5d1 tools/zmqsend: close the input FILE
Fixes CVE-2026-30998

Fixes: Resource leak
Found-by: Xinghang Lv
Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit 18b83f2d0a)
2026-09-19 16:59:28 +02:00
Michael Niedermayer
b3e09b5fe5 avcodec/ppc/vp8dsp: store the 16 pixel wide rows at any alignment
(cherry picked from commit 4be657ffd8)
2026-09-19 16:18:37 +02:00
Christopher Decker
3765be13dc 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>
(cherry picked from commit 94ff335d76)
Co-Authored-by: Fable 5
2026-09-19 16:18:37 +02:00
Lynne
b9575cfd6b vulkan_encode: fix leak and swallowed errors in init_base_units()
The encoded session parameters buffer was never freed, and both
GetEncodedVideoSessionParametersKHR error paths returned err, which
is always 0 at that point, reporting success on failure.

(cherry picked from commit b672ae3905)
Co-Authored-by: Fable 5
2026-09-19 16:18:37 +02:00
Raja-89
aed52cc81b avfilter/dnn: fix async teardown race condition in all backends
When the filter graph is torn down early (e.g. at EOF with -frames:v),
the main thread calls dnn_free_model and destroys the request queue
while async inference threads may still be running. When a detached
thread finishes and tries to push its result back to the destroyed
queue, it triggers a segmentation fault.

Add ff_dnn_wait_requests() to dnn_backend_common which blocks
until all allocated request items (ctx->nireq) have been safely
returned to the request_queue. Call it from dnn_free_model in the
torch, tensorflow, openvino, and onnx backends before destroying the queue.

(cherry picked from commit b52c71e438)
Co-Authored-by: Fable 5
2026-09-19 16:18:37 +02:00
Michael Niedermayer
9c5b819d62 update for 8.1.3
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 15:04:30 +02:00
Michael Niedermayer
e8c2decf6d avfilter/vf_decimate: reject blocks smaller than one chroma sample
Fixes: out of array access
Fixes: division by zero
Fixes: vdfZuLhrGLdR
Found-by: zhang xingxing

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 590fb407b0)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:20 +02:00
Michael Niedermayer
113150ff56 avformat/genh: check for unsupported interlaved size 1 typ1 THP
Fixes: use of uninitialized memory
Fixes: crafted_malicious.genh / generate_poc.py
Fixes: XtWk54O0PGfP
Found-by: zhang xingxing

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 4ebb720fc1)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:20 +02:00
Umar Pathan
54beaa2687 lavc/vvc: Prevent OOB write in sh_entry_points
Fixes: out of array access
Fixes: Af5rtPnOunVT
Found-by: Umar Pathan (Umar0x)
Signed-off-by: Umar Pathan <hello@umar.ac>
(cherry picked from commit a809a784ec)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:20 +02:00
Michael Niedermayer
2f52e998c4 avcodec/vulkan_hevc: bound the per category reference counts in vk_hevc_start_frame
Fixes: out of array write
Found-by: Michael Niedermayer with Forgejo Fairy
(cherry picked from commit 68845e26f7)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:20 +02:00
Kai Martin
d9fc7081aa avcodec/vulkan_hevc: bound the reference count in vk_hevc_start_frame
Fixes: out of array write
Fixes: 9vZSLhhnp3ps
Found-by: Kai Martin, KG3N Research
(cherry picked from commit e058af88ab)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:19 +02:00
David Tolnay
9a06aedb14 avcodec/fflcms2: fix memory leak after cmsDeleteContext(NULL)
At the time that this code was introduced into FFmpeg in April 2022 by commit
b9a25963f7, it was correct as written. The latest release of
lcms2 at the time was 2.13.1 in which `cmsDeleteContext(NULL)` was a no-op.

Since lcms2 version 2.15, released Mar 2023, the same call is no longer a no-op and
instead means destroy the global context. The new behavior is justifiable as being
consistent with the rest of lcms2's API, where passing NULL for a cmsContext argument
means operate on the global context. For example `cmsDupContext(NULL, ...)` constructs a
context duplicated from the global context; `cmsPluginTHR(NULL, ...)` registers a plugin
into the global context.

The upstream commit that introduced the behavior change for `cmsDeleteContext` is:
a9e4601ceb

In FFmpeg, the new behavior leads to a memory leak if `ff_icc_context_uninit` is ever
called on an `FFIccContext` without `ff_icc_context_init`. Here is why that can happen,
and here is how it leads to a memory leak.

Naively, uninitializing something which was never initialized seems like it shouldn't
happen, but in this case these contexts are *lazily* initialized and *unconditionally*
deinitialized. `FFIccContext` is a member of `AVCodecInternal`:

    // libavcodec/internal.h:148-150
    #if CONFIG_LCMS2
        FFIccContext icc; /* used to read and write embedded ICC profiles */
    #endif

It is initialized conditionally by the snippet of `detect_colorspace` shown below, or by
similary shaped code in libavcodec/encode.c. The `avci->icc.avctx` guards "has it already
been initialized". The early returns beforehand are codepaths for which `icc` will not be
initialized, and will remain all-zero as allocated by `av_mallocz` in
`ff_decode_internal_alloc`.

    // libavcodec/decode.c:534-542
    if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
        return 0;
    sd = av_frame_get_side_data(frame, AV_FRAME_DATA_ICC_PROFILE);
    if (!sd || !sd->size)
        return 0;
    if (!avci->icc.avctx) {
        ret = ff_icc_context_init(&avci->icc, avctx);

Later, `avci->icc` is uninitialized unconditionally by `ff_codec_close`:

    // libavcodec/avcodec.c:447-480
    if (avcodec_is_open(avctx)) {
        ...
    #if CONFIG_LCMS2
        ff_icc_context_uninit(&avci->icc);
    #endif

So every codec closed without `AV_CODEC_FLAGS2_ICC_PROFILES`, or without an ICC side-data
packet, reaches `ff_icc_context_uninit` on a never-initialized context.

As part of `cmsDeleteContext(NULL)` destroying lcms2's global context, it runs
`cmsUnregisterPlugins()` and destroys `globalContext.MemPool`. Since the global context is
shared by every user of lcms2 in the process, closing an FFmpeg codec silently tears down
unrelated libraries' lcms2 state. The most visible symptom is that
`_cmsRegisterMutexPlugin(NULL, NULL)` nulls out the mutex callbacks, after which
`cmsCloseProfile()` leaks each profile's `UsrMutex` and profiles opened later are left
without any locking at all.

The fix is to delete only contexts created by FFmpeg.

Signed-off-by: David Tolnay <dtolnay@gmail.com>
(cherry picked from commit 705286a8a7)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:19 +02:00
Wu Jianhua
890bcd314e avcodec/cbs_h266_syntax_template: fix ph_recovery_poc_cnt range
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
(cherry picked from commit c877e20d7e)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:19 +02:00
jiangjie
7ba9579ae5 avformat/http: free cookie parameters on parse failure
Fixes issue #24172

(cherry picked from commit 89153eb701)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:19 +02:00
Niklas Haas
c0ddaa9f38 avutil/opt: fix av_opt_is_set_to_default() on default-NAN options
Affects filters like vf_tonemap, vf_nlmeans_vulkan and vf_zscale that use
NAN as an explicit default value to indicate "not set by user".

Signed-off-by: Niklas Haas <git@haasn.dev>
(cherry picked from commit 5815e6343c)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:19 +02:00
张永鹏
da37798dfd fftools: reject negative -t durations
Reject negative recording durations for input and output -t before they reach streamcopy or trim handling. Keep -t 0 accepted.

Signed-off-by: 张永鹏 <roc63@outlook.com>
(cherry picked from commit 629a5b4b0f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:18 +02:00
Kacper Michajłow
2560bec4ed avcodec/hevc: don't error out on remaining slices of a skipped picture
When the first slice of a picture is skipped, an undecodable RASL
after a seek or avctx->skip_frame, the remaining slices were still
parsed against the stale context and failed the PPS change, dependent
slice, or missing first slice checks, logging a decoding error per
slice. Drop them before parsing instead.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
(cherry picked from commit e5eb7581dd)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:18 +02:00
Frank Plowman
c96d402ff1 avcodec/vvc: Skip over the current picture in find_ref_idx
In VVC, there are two schemes for addressing reference pictures in
the DPB:
1. Normally, the POC of the reference picture is signaled using a delta
   from the current picture POC.
2. In the case of long-term reference pictures (LTRPs), which may be far
   away from the current POC, the absolute value of the LTRP POC is
   signalled.  This scheme has two sub-schemes:
   a. Signalling the entirety of the absolute value of the LTRP
      POC would be expensive, so in most cases we only signal the
      sps_log2_max_pic_order_cnt_lsb_minus4 + 4 least-significant bits
      of the LTRP POC.
   b. In the case of a collision in the least-significant bits,
      the full POC is signalled.

Both schemes are implemented in find_ref_idx.  The use_msb parameter
of find_ref_idx is nonzero in the case of schemes 1 and 2b, and zero in
the case of scheme 2a.

This commit fixes a bug in scheme 2a.  The issue arises from the fact
that the current picture is stored in the DPB at the time find_ref_idx
is invoked in FFmpeg's implementation, whereas in the specification the
current picture is not yet considered part of the DPB.  The current
picture may have a POC which shares least-significant bits with an LTRP.
The specification does not identify this as a collision however (see the
condition in 7.4.10, under the semantics of
delta_poc_msb_cycle_present_flag), and so scheme 2a is used rather than
scheme 2b.  If the current frame precedes the correct LTRP in the DPB,
FFmpeg's implementation then interprets the signalling to mean a frame
which references itself.  The problematic callsite identifies this as an
issue and returns an AVERROR_INVALIDDATA, but this scenario can occur in
valid bitstreams.  For example, the conformance bitstream
LTRP_A_ERICSSON_3 has one such instance.  FFmpeg gets away with decoding
it currently because the LTRP precedes the current picture in the DPB,
but this is by chance rather than design.

The commit addresses this issue by skipping over the current picture
inside the main loop of find_ref_idx.  An unambiguous reference to the
current picture is still syntactically possible but illegal when using
scheme 2b.  The handling of this case is moved from find_ref_idx to the
caller, which allows for simplifying find_ref_idx.

Signed-off-by: Frank Plowman <post@frankplowman.com>
(cherry picked from commit 2b3609ab61)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:18 +02:00
Andreas Rheinhardt
6245c7612a avcodec/mips/vc1dsp_msa: Fix mspel functions
The VC-1 mc prediction for combined horizontal and vertical offset
involves first a vertical 4-tap filter, followed by shifting,
followed by a horizontal 4-tap filter, followed by shifting by 7.
Both passes involve negative coefficients and therefore the
intermediate values for the >> 7 can exceed the range of
0..255*128 a bit in both directions. Therefore one can not simply
use either a logical or an arithmetic right shift. But one can use
them after having added a certain bias to ensure that one is in
the proper range. This is what this commit does.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit 0056dd32fd)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:18 +02:00
Andreas Rheinhardt
82e8b20f3d avcodec/mips/hevcpred_msa: Fix compilation
Broken in ba56a300a9,
ba56a300a9 and again
in 38b8ae4112.

This means that no has compiled git master on mips
since 2024-06-04. And no one complained.

Hint: One still needs to pass -flax-vector-conversions
here in order to compile this file.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit d5b8439bdd)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:18 +02:00
J. Brandt Buckley
a996d156da avcodec/vc1_block: don't drop the last macroblock when 1 bit remains
The P- and B-picture per-MB guards added in 2a8785966c bail out of the loop
to error concealment when get_bits_left() <= 1, but P- and B-picture MBs can
legitimately cost exactly 1 bit in certain cases. This patch relaxes the guards
to accommodate those cases.

## Explanation

With the SKIPMB bitplane in Raw mode a skipped macroblock is a single SKIPMBBIT
(SMPTE ST 421:2013, 7.1.3.7, p.109) and then "may only contain the HYBRIDPRED
syntax element" (8.3.4.4, p.140), which is only read when predictors A and C
are in-bounds and the predicted vector differs from A or C by more than 32
quarter-pels (8.3.5.3.5, Figure 55, pp.149-150). That condition isn't met in a
static region so such a MB costs just 1 bit. A direct+skipped B-picture MB
likewise reads nothing beyond its raw flag (Table 30, p.86).

In Simple/Main profile a picture is byte-aligned with no stop bit, so if a
picture ends with a 1-bit skipped macroblock and its last coded bit lands on a
byte boundary, the final MB is reached with exactly one bit left. The guard
then conceals a valid macroblock, sets FF_DECODE_ERROR_CONCEALMENT_ACTIVE
on an undamaged frame, and the damage propagates to every frame up to the next
keyframe. (Advanced Profile BDUs end in a trailing '1' bit per Annex E.2/E.3
p.437, so they always have at least two bit left and are therefore unaffected.)

## Reproducing

Reproducible with an existing sample (prior to this patch):

    $ ffmpeg -i https://samples.ffmpeg.org/V-codecs/WMV9/wmv-samples/sample-wmv9-simple-SP@ML.wmv -map 0:v -f null - 2>&1 | grep -A1 concealing
    [wmv3 @ 0x122605430] concealing 75 DC, 75 AC, 75 MV errors in P frame
    [vist#0:0/wmv3 @ 0x122604080] [dec:wmv3 @ 0x122604df0] corrupt decoded frame
    [wmv3 @ 0x122605430] concealing 50 DC, 50 AC, 50 MV errors in P frame
    [vist#0:0/wmv3 @ 0x122604080] [dec:wmv3 @ 0x122604df0] corrupt decoded frame
    [wmv3 @ 0x122605430] concealing 100 DC, 100 AC, 100 MV errors in P frame
    [vist#0:0/wmv3 @ 0x122604080] [dec:wmv3 @ 0x122604df0] corrupt decoded frame

## References

- SMPTE ST 421:2013 spec: https://pub.smpte.org/doc/st421/20131008-pub/

Signed-off-by: J. Brandt Buckley <brandt@runlevel1.com>
(cherry picked from commit ec8411e854)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:18 +02:00
Kacper Michajłow
cc971e5cf1 avcodec/dovi_rpudec: strip zero padding
ef167512ab changed to parse RPU forward as far as we can go, but also
removed zero padding trimming, so the ext block size check on files with
big padding could trigger now. Restore the trailing zero strip. Note
that this does care only about zero padded NALs, while we have seen some
files with garbage padding, they are not considered here.

The only real way to find the end of RPU is to compute CRC32, as the
0x80 byte may be ambiguous. But we don't want that, and most (all) files
don't need that.

Also adjust the ext block remaining size check to minimal possible
(block with 0 size).

Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/24428
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
(cherry picked from commit 22b96de803)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:17 +02:00
Steven Liu
400fe9454f avformat/dashdec: check fragment_timescale before division in refresh_manifest
fix issue: issues/23057 POC4

In refresh_manifest(), when timelines are present, fragment_timescale is
used as the denominator to compute currentTime. If fragment_timescale is
zero (e.g., timescale attribute missing from a crafted manifest with
SegmentTimeline), this results in a division by zero.

Add fragment_timescale > 0 guard to both the video and audio timeline
processing paths to prevent the crash.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
(cherry picked from commit 6a351a3113)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:17 +02:00
tangsha
5a21a006cb avutil/encryption_info: reject init info with zero-sized key IDs
av_encryption_init_info_alloc() only allocates key_ids when key_id_size is
non-zero, but stores num_key_ids regardless. If num_key_ids is non-zero and
key_id_size is 0, the returned object has a NULL key_ids array alongside a
non-zero num_key_ids. av_encryption_init_info_free(),
av_encryption_init_info_get_side_data() and
av_encryption_init_info_add_side_data() then loop over num_key_ids and
dereference key_ids[i], leading to a null pointer dereference.

Reject the num_key_ids > 0 && key_id_size == 0 combination instead of
returning an inconsistent object.

Signed-off-by: tangsha <tangsha@kylinos.cn>
(cherry picked from commit 9fc8c785e2)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:17 +02:00
unfunnyatearug
1aa713eeb8 avformat/genh: check thp extradata read and allocation
the genh demuxer had the same short-read issue at one location. the read is now performed with `ffio_read_size()` so truncated input is rejected instead of leaving uninitialized data in the extradata.
`ff_alloc_extradata()` also had its return value unchecked. if allocation failed, the code could dereference a null pointer. the return value is now checked.
the affected path is capped at two channels, so the potential information leak is relatively small, but it is the same underlying bug class.

Signed-off-by: unfunnyatearug <yalisib2222@gmail.com>
(cherry picked from commit 4b47405e1c)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-19 14:27:17 +02:00