Commit graph

275 commits

Author SHA1 Message Date
Timo Rothenpieler
262d41c804 all: fix typos found by codespell 2025-08-03 13:48:47 +02:00
Timo Rothenpieler
8d439b2483 all: fix whitespace/new-line issues 2025-08-03 13:48:47 +02:00
Frank Plowman
f82748d5e0 lavc/vvc: Mark SPS used if multiple CLVSSs use it
Consider the following sequence of NALUs (with some PPSs etc. omitted
for brevity):
1. SPS (ID=0, content=A)
2. IDR (SPS=0)
3. IDR (SPS=0)
4. SPS (ID=0, content=B)
5. TRAIL (SPS=0)

When decode_sps is called for NALU 3., ps->sps_id_used is cleared as
IDRs are one way of forming a CLVSS.  Then, old_sps is non-NULL
containing the result of calling decode_sps for NALU 2.  We haven't
received any SPSs between NALUs 2. and 3., therefore old_sps and rsps
are identical and the function returns.  The issue is that, at this
point, ps->sps_id_used is still zero despite the SPS being used for IDR
3.  This results in the check for conflicting SPSs not working properly
when decode_sps is called for NALU 5., allowing prediction between
pictures with different SPSs and probably all sorts of other
shenanigans.

Patch addresses the problem outlined above by also setting
ps->sps_id_used in the early return case.
2025-08-02 15:04:39 +00:00
Frank Plowman
7c5319e692
lavc/vvc: Add max parameter to kth_order_egk_decode
Prior to this patch, kth_order_egk_decode could read arbitrarily
large values which then overflowed and caused various issues.
Patch fixes this by making kth_order_egk_decode falliable,
requiring the caller to specify an upper bound and returning an
error if the read value would exceed that bound.

This patch resolves the same issue as
eb52251c0a, but I think this is the proper
fix as it also addresses issues with syntax elements besides
ff_vvc_num_signalled_palette_entries.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-07-28 20:46:10 +01:00
Frank Plowman
ce172bc362
lavc/vvc: Don't discard palette_subblock_data return code
Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-07-28 20:45:45 +01:00
Andreas Rheinhardt
d20a4ef93c avcodec/vvc/dec: Don't use GetBit-API when byte-aligned
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-07-11 15:13:21 +02:00
Michael Niedermayer
eb52251c0a
avcodec/vvc/ctu: Check ff_vvc_num_signalled_palette_entries
Fixes: index 107 out of bounds for type 'uint16_t const[63]'
Fixes: 421336912/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VVC_fuzzer-6436225806565376

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-07-06 19:25:47 +02:00
Michael Niedermayer
9d1e4feece
avcodec/vvc/ctu: Check palette_escape_val
Fixes: integer overflow
Fixes: 418314174/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VVC_fuzzer-4871731867353088

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-07-06 19:24:52 +02:00
Marvin Scholz
7d38486975 avcodec/vvc/refs: remove early return
The ret value is checked later on again, so this check
is redundant and would cause the frame to not be unrefd on
failure as well.

So remove this check and add one before av_frame_remove_side_data
to ensure it is not called with an invalid frame.

Fix CID 1648350

Reviewed-by: Frank Plowman <post@frankplowman.com>
2025-06-28 15:16:45 +02:00
Frank Plowman
540a2497d2
lavc/vvc: Fix condition for using default scaling factor
Add handling here for
sps_scaling_matrix_for_alternative_colour_space_disabled_flag.

Also add parentheses to make behaviour a little more explicit,
where &&'s precedence over || was relied on previously.

Reported-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-06-27 06:06:14 +09:00
Marvin Scholz
9ad6dca28c avcodec/vvc: parse all SEI messages
While the current code iterated over the messages, it always returned
in the first iteration. Instead keep iterating and warn for failure to
parse. At time of writing, none of the parsing functions seems to
actually return an error, ever.

Fix CID 1648348
2025-06-12 21:17:07 +08:00
Marvin Scholz
3d7668dae1 avcodec/vvc/dec: fix possible null-pointer dereference
When checking for filmgrain here, needs_fg can be true even when
film_grain_characteristics is NULL (when aom_film_grain.enable is true),
therefore this check could end up dereferencing film_grain_characteristics
even though it is NULL.

Fix CID 1648347
2025-06-12 21:16:46 +08:00
Frank Plowman
81370fd796 lavc/vvc: Fix unchecked return code and shadowing
Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-06-07 19:26:11 +08:00
Wu Jianhua
a02e880e35 avcodec/vvc/sei: add decode_mastering_display_colour_volume
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
f6d2f38530 avcodec/vvc/sei: add decode_ambient_viewing_environment
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
761f75db74 avcodec/vvc: support fields
passed files:
    FIELD_A_Panasonic_4.bit
    FIELD_B_Panasonic_2.bit

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
870fa133af avcodec/vvc/sei: add decode_frame_field_info
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
97137e38c1 avcodec/vvc/sei: add decode_content_light_level_info
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
40bc5e119e avcodec/vvc/sei: add decode_display_orientation
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
23e9912315 avcodec/vvcdec: verify picture hash
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
8dfc24cdce avcodec/vvc/sei: add decode_decoded_picture_hash
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
312f8ef2ca avcodec/vvc/dec: support removing film grain params from side data
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
a8d949bd96 avcodec/vvc/dec: support applying film grain by the decoder
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
1608d60001 avcodec/vvc/dec: export sei to the frame when the frame starts
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
1c87e3625a avcodec/vvc/sei: add decode_film_grain_characteristics
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Wu Jianhua
ab5df96cef avcodec/vvc: support decoding prefix and suffix nal units
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-31 09:35:54 +08:00
Frank Plowman
0382291811 lavc/vvc: Fix divide-by-zero in LMCS param derivation
Add three missing requirements on bitstream conformance from 7.4.3.19 of
H.266 (V3).  Issue found using fuzzing.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-05-25 09:35:21 +08:00
Frank Plowman
670089304a lavc/vvc: Avoid UB in DB strength derivation for PLT CUs
When called for palette-predicted CUs, boundary_strength could cause
undefined behaviour due to accessing uninitialised motion information.
The spec doesn't include this, but in the reference software it seems
the deblock strength is always set to 0 for palette CUs due to some
implementation details: perhaps this is a spec issue?

Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-05-24 21:50:46 +08:00
Frank Plowman
a18b2c2696 lavc/vvc: Detect subpic overlaps at CTU level
In d5dbcc00d8, it was hoped that detection
of subpicture overlaps could be performed at the tile level, so as to
avoid introducing per-CTU checks. Unfortunately since that patch,
fuzzing has indicated there are some structures involving
pps_subpic_one_or_more_tiles_slice where tile-level checking is not
sufficient.  Performing the check at the CTU level should (touch wood)
be the be-all and and-all of this, as CTUs are the lowest common
denominator of the picture partitioning.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2025-05-24 10:57:20 +08:00
Nuo Mi
363a7a34f6 lavc/vvc/plt: validate run and signalled_entries
Fixes a crash triggered by a fuzzed clip:
https://github.com/ffvvc/tests/tree/main/fuzz/passed/000256.bit

Reproduce with:
ffmpeg -i 000256.bit -f null -
2025-05-24 10:36:19 +08:00
Wu Jianhua
fd5d754b2a avcodec/vvc: add adaptive color transform support
passed files:
    ACT_A_Kwai_3.bit
    ACT_B_Kwai_3.bit

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
0e4c0db317 avcodec/vvc/intra: refact out lmcs_scale_chroma and add_residual
prepare for adaptive color transform

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
ff1ecc7eb3 avcodec/vvc/intra: make lmcs_scale_chroma inplace
prepare for adaptive color transform

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
d2e7ca684c avcodec/vvc/intra: refact, predict jcbcr to tb->coeffs
prepare for adaptive color transform

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
86e96a1c02 avcodec/vvc/intra: fix scaling process for transform coefficients
See 8.7.3 Scaling process for transform coefficients

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
fef573f30b avcodec/vvc/dsp: add adaptive_color_transform
See 8.7.4.6 Residual modification process for blocks using colour space conversion

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
8bdad76c00 avcodec/vvc/dsp: update the interface of pred_residual_joint for joint cbcr residual functionality
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
d00a249dbf avcodec/vvc/ctu: fix derive_chroma_intra_pred_mode
See 8.4.3 Derivation process for chroma intra prediction mode

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
c58357edc2 avcodec/vvc/ctu: read act_enabled_flag for adaptive color transform
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
b9c5fb0d00 avcodec/vvc/cabac: add ff_vvc_cu_act_enabled_flag
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
70a2d0d756 avcodec/vvc/intra: add palette coding decoder
Introduction at https://ieeexplore.ieee.org/document/9408666

passed files:
    10b422_G_Sony_5.bit
    10b422_H_Sony_5.bit
    10b422_I_Sony_5.bit
    10b422_J_Sony_5.bit
    10b422_K_Sony_5.bit
    10b422_L_Sony_5.bit
    8b422_G_Sony_5.bit
    8b422_H_Sony_5.bit
    8b422_I_Sony_5.bit
    8b422_J_Sony_5.bit
    8b422_K_Sony_5.bit
    8b422_L_Sony_5.bit
    8b444_A_Kwai_2.bit
    8b444_B_Kwai_2.bit
    PALETTE_A_Alibaba_2.bit
    PALETTE_B_Alibaba_2.bit
    PALETTE_C_Alibaba_2.bit
    PALETTE_D_Alibaba_2.bit
    PALETTE_E_Alibaba_2.bit

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
95473fae9b avcodec/vvc/filter: skip deblocking filter for palette
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
26215b8c83 avcodec/vvc/ctu: add palette support
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
fd85f83608 avcodec/vvc/intra: add ff_vvc_palette_derive_scale
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
3ecf8f8766 avcodec/vvc/ctu: refact out intra_data
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
d0f9151eb0 avcodec/vvc: refact, save pf and ciip_flag in ff_vvc_set_intra_mvf
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
75e5fb6e37 avcodec/vvc: refact out ep_init and ep_init_wpp
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
cfea9b88a5 avcodec/vvc/ctu: refact out ff_vvc_channel_range
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
89ba1bb255 avcodec/vvc/cabac: add palette support
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00
Wu Jianhua
a7320efa2b avcodec/vvc/cabac: add 9.3.3.7 Fixed-length binarization process
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2025-05-17 09:22:40 +08:00