Commit graph

52047 commits

Author SHA1 Message Date
Michael Niedermayer
c06f5b3ab9
avcodec/svq3: Check there are bits left before decompression
Fixes: out of array read
Fixes: 402587670/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SVQ3_fuzzer-6343867775647744

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-15 03:03:56 +02:00
Michael Niedermayer
fd0a792766
avcodec/sonic: Check num_taps
The encoder uses max 128 taps, which is quiet a lot already
If work is done to improve sonic, it will be more radical than changing the taps

Fixes: Timeout
Fixes: 402539974/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-6122944271286272

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-15 03:03:56 +02:00
Michael Niedermayer
76e29bb8bf
avcodec/dnxuc_parser: Use ff_parse_close()
Fixes: buffer leak
Fixes: 398894512/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-6716597473705984

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-15 03:03:54 +02:00
Andreas Rheinhardt
0d7172a9ff avcodec/cbs: Avoid branch
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-15 01:51:34 +02:00
Andreas Rheinhardt
f71d0f0559 avcodec/apv_parser: Mark close as av_cold
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-15 01:51:34 +02:00
Andreas Rheinhardt
d794ecd9d2 avcodec/vulkan_encode_hevc: Fix memleak on error
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-15 01:51:28 +02:00
Andreas Rheinhardt
70fa44dfa8 avcodec/vulkan_encode_h264: Fix memleak on error
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-15 01:26:07 +02:00
Shaun Loo
bed1769957 x86/vvcdec: sao, add avx2 support
This is a part of Google Summer of Code 2023

Co-authored-by: Nuo Mi <nuomi2021@gmail.com>
2025-05-14 20:55:39 +08:00
Shaun Loo
69f63c6210 x86/hevcdec: refact, remove duplicate code in HEVC_SAO_{BAND, EDGE}_FILTER
This is a part of Google Summer of Code 2023

Co-authored-by: Nuo Mi <nuomi2021@gmail.com>
2025-05-14 20:55:39 +08:00
Shaun Loo
dbd859a186 x86/hevcdec: sao, refact out h26x macros
This is a part of Google Summer of Code 2023

Co-authored-by: Nuo Mi <nuomi2021@gmail.com>
2025-05-14 20:55:39 +08:00
Nuo Mi
62f3d7e027 x86/vvcdec: misc, reordered functions in dsp_init for improved readability 2025-05-14 20:55:39 +08:00
James Almer
038314bc6b avcodec/exr: reindent after the previous change
Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-14 00:17:02 -03:00
Mark Thompson
527d5eaec7 apv_decode: Discard invalid run codes earlier
Caught by ubsan - would cause an invalid shift in constructing the
run value.
2025-05-13 20:52:35 +01:00
Mark Thompson
1ad57a847e lavc: Add unit test for APV entropy decode 2025-05-13 19:37:53 +01:00
Mark Thompson
a3c8fba5da apv_decode: Multisymbol entropy decode 2025-05-13 19:37:49 +01:00
Michael Niedermayer
74fd2c3ddb
avcodec/h264_mb: Fix tmp_cr for arm
When decoding a bitstream with weighted-bipred enabled,
the results on ARM and x86 platforms may differ.

The reason for the inconsistency is that the value of
STRIDE_ALIGN differs between platforms. And STRIDE_ALIGN
is set to the buffer stride of temporary buffers for U
and V components in mc_part_weighted.

If the buffer stride is 32 or 64 (as on x86 platforms),
the U and V pixels can be interleaved row by row without
overlapping, resulting in correct output.
However, on ARM platforms where the stride is 16,
the V component did overwrite part of the U component's pixels,
leading to incorrect predicted pixels.

The bug can be reproduced by the following bitstream.

https://trac.ffmpeg.org/attachment/ticket/11357/inter_weighted_bipred2.264

Fixes: ticket 11357
Commit-msg-mostly-by: Bin Peng <pengbin@visionular.com>
Reviewed-by: Bin Peng <pengbin@visionular.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-13 00:20:23 +02:00
Michael Niedermayer
fd5a3c5fed
avcodec/vorbisdec: Dont treat overread as error
This differs from libvorbis by
stddev:    2.44 PSNR: 88.58 MAXDIFF:   41 bytes:   834304/   834304
for the file from the ticket

Fixes: Ticket11427

Regression since: dc89cf804a

This is a similar solution to what james proposed earlier in
[FFmpeg-devel] [PATCH] avcodec/vorbisdec: don't abort on EOD when decoding residuals

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-13 00:08:02 +02:00
Michael Niedermayer
4e5523c985
avcodec/hevc/ps: Fix dependant layer id check
Fixes: shift exponent 49 is too large for 32-bit type 'int'
Fixes: 398060145/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5023082406543360

Reviewed-by: James Almer <jamrial@gmail.com>
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-09 22:27:04 +02:00
Michael Niedermayer
9230c93cc9
avcodec/rv60dec: inter also fails with qp >= 32
Fixes: out of array read in decode_cu_16x16()
Fixes: 398049430/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RV60_fuzzer-5525836849807360

Reviewed-by: Peter Ross <pross@xvid.org>
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-09 22:27:04 +02:00
Michael Niedermayer
43926e026d
avcodec/mmvideo: fix palette index
Fixes: 391935573/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MMVIDEO_fuzzer-4655048979709952
Fixes: out of array access

Reviewed-by: Peter Ross <pross@xvid.org>
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-05-09 22:26:51 +02:00
Manuel Lauss
37064b2d16
avcodec/sanm: support "StarWars - Making Magic" video
Videos of "StarWars - Making Magic" consist of 640x480 codec3 frames
which establish a background, and a 320x240 codec48 video put on top
at random left/top offsets.

To support this, a new default buffer "fbuf", which holds the final
image to be presented, is added, since codec37/47/48 need their 2/3 buffers
to be private to themselves.  The decoded result is then copied to the fbuf,
honoring the left/top offsets if required.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-05-09 07:29:15 +02:00
Manuel Lauss
9369ebf238
avcodec/sanm: recognize common FOBJ sizes
Change the size detection a bit to recognize common video sizes,
as the FOBJ codecs>=37 cannot always be trusted, since they can
be embedded in a larger frame.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-05-09 07:29:13 +02:00
Manuel Lauss
7f0b7b0496
avcodec/sanm: ignore codec48 compression type 6
Some videos of "StarWars - Making Magic" have this subcompression
type: data just consists of the 16 byte codec48 header; the DOS player
and the c48 decoder in the "Mysteries of the Sith" game engine ignore it.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-05-09 07:29:08 +02:00
James Almer
244ad944e9 avcodec/liboapvenc: remove 4:4:4 support until it's properly handled
liboapv will seemingly encode correct 4:4:4 output, but report profile_idc 33, which
is specifically the profile value for 4:2:2 10bit.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-07 21:40:08 -03:00
Mark Thompson
9bf54cdb19 cbs_apv: Check tile component sizes
It was possible for the buffer pointers for the last tile to go over the
end of the unit buffer leading to a read overflow during decode of the
macroblock layer.  Check all tile component sizes to prevent this case
and also catch related tile size mismatch errors earlier.
2025-05-05 17:22:57 +01:00
Mark Thompson
ea457e54e1 apv_entropy: Improve robustness to bitstream errors 2025-05-05 17:22:57 +01:00
Mark Thompson
2aa2095bb4 cbs_apv: Better constrain tile_width/height_in_mbs
The maximum number of tile columns/rows adds an extra constraint on
the minimum tile width/height for large frames (over 5120 width or
2560 height).
2025-05-05 17:22:57 +01:00
Mark Thompson
1a9a2bafc8 apv_decode: Improve reporting of decode errors
Halt tile component decoding at the first entropy error (this will be a
desync and is not recoverable).  If any tile components contain errors
then discard the frame unless the output-corrupt flag is set.

Also fixes CID 1646764, which is the error case where the tile component
is too large for get_bits to handle.
2025-05-05 17:22:57 +01:00
Mark Thompson
5acd2145a4 apv_decode: Fix memory leak on decode error 2025-05-05 17:22:57 +01:00
Mark Thompson
135acc8e61 cbs_apv: Always restore tracing state on split fragment error
Fixes CID 1646769.
2025-05-05 17:22:57 +01:00
James Almer
a9557c1f26 avcodec/apv_decode: build the lut table only once
No reason to build the exact same table once per decoding thread.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-05 13:19:29 -03:00
James Almer
0af1d69959 avcodec/hevc/hevcdec: move the slice header buffer overread check up in the function
Abort as soon as we're done reading the slice header instead of running extra checks
that assume slice data may follow.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-05 12:55:03 -03:00
James Almer
d34c738435 avcodec/hevc/hevcdec: ensure a bit was read when checking for alignment_bit_equal_to_one
Prevents printing bogus errors about the value being 0, when in fact we
overread the available slice buffer.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-05 12:55:03 -03:00
James Almer
d08c5527cf avcodec/exr: add support for half-float DWAA/B compression
Fixes ticket #11555.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-04 16:22:28 -03:00
James Almer
0cabfdc8bc avcodec/apv_parser: use an AVBufferRef to avoid data copying
Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-04 16:22:14 -03:00
James Almer
4bfe9c5663 avcodec/cbs: add an AVBufferRef input argument to ff_cbs_read()
To allow taking a reference from an existing buffer outside of AVPackets.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-04 16:22:14 -03:00
Dawid Kozinski
fab691edaf avcodec: add APV encoder using liboapv
Co-authored-by: James Almer <jamrial@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-04 16:21:35 -03:00
James Almer
c4ea4abec2 avcodec: add an APV parser
Signed-off-by: James Almer <jamrial@gmail.com>
2025-05-01 22:42:34 -03:00
Lynne
707c04fe06
ffv1enc_vulkan: support 8 and 16-bit 2-plane YUV formats
This adds support for all 8-bit and 16-bit 2-plane formats.
P010 and others require more work as the data's LSB-padded.
2025-05-01 09:34:44 +02:00
Lynne
9c0349cca1
aacdec_usac: correct Mps212 parsing location
It gets parsed after SBR, even if there is no SBR.
2025-05-01 09:34:39 +02:00
James Almer
e80f32f3bd avcodec/cbs_apv: don't return an error when reading empty buffers
The output will be a fragment with zero units, which is a lot more user friendly
than making them think something went wrong, as it already happens with cbs_av1.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-04-30 19:15:19 -03:00
Mark Thompson
585455f7b3 apv_decode: Replace division with shift
The compiler can't see that this should be a shift and generates a real
division which is slow enough to appear in profiles on its own.
2025-04-30 22:57:56 +01:00
Andreas Rheinhardt
0b588bfb51 avcodec/apv_dsp: Fix left-shift of negative value
Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-04-30 23:38:21 +02:00
Shiyou Yin
ab8e160f71
avcodec: Fix fate-checkasm-hevc_pel failed on LA.
Some loop counters were initialized incorrectly.
This patch enhances the handling of loop iterations and residual parts.

Reviewed-by: 陈昊 <chenhao@loongson.cn>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-04-29 22:59:23 +02:00
Zhao Zhili
25812d3033 avcodec/bsf/h264_mp4toannexb: Fix mixed bitstream format
This bsf converts AV_PKT_DATA_NEW_EXTRADATA side data in avcc format
to in-band annexb format. However, the side data wasn't been removed
and copied from input packet to output packet. So the output packet
has mixed bitstream format. We don't support mixed bitstream format.
For example, h264_metadata report error in the following case:

ffmpeg -i foo.flv \
  -bsf:v "h264_mp4toannexb,h264_metadata" \
  -c copy -f null

This patch removed NEW_EXTRADATA side data after process.

This patch also add a check so only NEW_EXTRADATA in avcc format is
processed. NEW_EXTRADATA in annexb format is copied to output as is.

Reported-by: jiangjie <jiangjie618@gmail.com>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-04-29 15:25:08 +08:00
Zhao Zhili
26752368f0 aarch64/h26x: Add put_hevc_pel_bi_w_pixels
On rpi5 (A76):

put_hevc_pel_bi_w_pixels4_8_c:                          90.0 ( 1.00x)
put_hevc_pel_bi_w_pixels4_8_neon:                       34.1 ( 2.64x)
put_hevc_pel_bi_w_pixels6_8_c:                         188.3 ( 1.00x)
put_hevc_pel_bi_w_pixels6_8_neon:                       73.5 ( 2.56x)
put_hevc_pel_bi_w_pixels8_8_c:                         327.1 ( 1.00x)
put_hevc_pel_bi_w_pixels8_8_neon:                       75.8 ( 4.32x)
put_hevc_pel_bi_w_pixels12_8_c:                        728.8 ( 1.00x)
put_hevc_pel_bi_w_pixels12_8_neon:                     186.1 ( 3.92x)
put_hevc_pel_bi_w_pixels16_8_c:                       1288.1 ( 1.00x)
put_hevc_pel_bi_w_pixels16_8_neon:                     268.5 ( 4.80x)
put_hevc_pel_bi_w_pixels24_8_c:                       2855.5 ( 1.00x)
put_hevc_pel_bi_w_pixels24_8_neon:                     723.8 ( 3.95x)
put_hevc_pel_bi_w_pixels32_8_c:                       5095.3 ( 1.00x)
put_hevc_pel_bi_w_pixels32_8_neon:                    1165.0 ( 4.37x)
put_hevc_pel_bi_w_pixels48_8_c:                      11521.5 ( 1.00x)
put_hevc_pel_bi_w_pixels48_8_neon:                    2856.0 ( 4.03x)
put_hevc_pel_bi_w_pixels64_8_c:                      21020.5 ( 1.00x)
put_hevc_pel_bi_w_pixels64_8_neon:                    4699.1 ( 4.47x)

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-04-29 15:24:14 +08:00
Zhao Zhili
39786f8cd5 aarch64/h26x: optimize sao_band_filter
int8_t[] is enough for offset_table of 8 bit streams.

On rpi5:
                             Before               After
hevc_sao_band_8_8_c:          252.3 ( 1.00x)     252.3 ( 1.00x)
hevc_sao_band_8_8_neon:        95.8 ( 2.63x)      61.0 ( 4.57x)
hevc_sao_band_16_8_c:         875.2 ( 1.00x)     864.9 ( 1.00x)
hevc_sao_band_16_8_neon:      317.5 ( 2.76x)     150.0 ( 6.26x)
hevc_sao_band_32_8_c:        3853.5 ( 1.00x)    3871.6 ( 1.00x)
hevc_sao_band_32_8_neon:     1222.3 ( 3.15x)     550.6 ( 7.39)
hevc_sao_band_48_8_c:        8203.6 ( 1.00x)    8182.6 ( 1.00x)
hevc_sao_band_48_8_neon:     2685.7 ( 3.05x)    1185.8 ( 7.36x)
hevc_sao_band_64_8_c:       14023.0 ( 1.00x)   14038.9 ( 1.00x)
hevc_sao_band_64_8_neon:     4783.2 ( 2.93x)    2078.4 ( 7.15x)

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-04-29 15:11:45 +08:00
Andreas Rheinhardt
fcc562693e avcodec/apv_decode: Remove redundant log message
ff_thread_get_buffer() already emits its own logmessage.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-04-27 23:00:10 +02:00
Andreas Rheinhardt
e2fcf234e4 avcodec/apv_decode: Fix shadowing
Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-04-27 23:00:07 +02:00
Mark Thompson
de42e06b5b lavc: APV metadata bitstream filter 2025-04-27 15:52:30 +01:00