Commit Graph

34 Commits

Author SHA1 Message Date
Andreas Rheinhardt ab2173c0a5 avcodec/cbs_h2645: Avoid function pointer casts, fix UB
The SEI message read/write functions are called
via function pointers where the SEI message-specific
context is passed as void*. But the actual function
definitions use a pointer to their proper context
in place of void*, making the calls undefined behaviour.
Clang UBSan 17 warns about this.

This commit fixes this by adding wrapper functions
(created via macros) that have the right type that
call the actual functions. This reduced the number of failing
FATE tests with UBSan from 164 to 85 here.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-25 13:42:47 +01:00
James Almer 6edcdd2520 avcodec/cbs_h265: support general_profile_idc 11
And fix support for general_profile_idc 9 and 10.
Defined in ITU-T H.265 (V6).

Signed-off-by: James Almer <jamrial@gmail.com>
2021-09-22 16:31:35 -03:00
Michael Niedermayer 85413a5ae6 avcodec/cbs_h265_syntax_template: Limit sps_num_palette_predictor_initializer_minus1 to 127
Fixes: index 128 out of bounds for type 'uint16_t [128]'
Fixes: 38651/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-6296416058736640

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-09-21 19:20:56 +02:00
James Almer 794e15fd54 cbs_h265: add support for Film Grain Characteristics SEI message
Signed-off-by: James Almer <jamrial@gmail.com>
2021-08-06 09:56:44 -03:00
Mark Thompson b128b0ce22 cbs_h265: Detect more reference combinations which would overflow the DPB
In total, the number of short term references (from the selected short
term ref pic set), the number of long term references (combining both the
used candidates from the SPS and those defined in the slice header) and
the number of instances of the current picture (usually one, but can be
two if current picture reference is enabled) must never exceed the size
of the DPB.  This is a generalisation of the condition associated with
num_long_term_pics in 7.4.7.1.

We use this to apply tighter bounds to the number of long term pictures
referred to in the slice header, and also to detect the invalid case where
the second reference to the current picture would not fit in the DPB (this
case can't be detected earlier because an STRPS with 15 pictures can still
be valid in the same stream when used with a different PPS which does not
require two DPB slots for the current picture).

Fixes: 24913/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-6261760693370880
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Tested-by: Michael Niedermayer <michael@niedermayer.cc>
2021-03-12 22:45:33 +00:00
Mark Thompson 8843607f49 cbs_h2645: Merge SEI message handling in common between codecs 2021-01-21 17:13:54 +00:00
Mark Thompson 773857df59 hevc: Use common SEI types 2021-01-21 17:13:54 +00:00
Mark Thompson 4bf3384800 cbs_h2645: Merge SEI messages in common between codecs
Make a new template file for common SEI messages - this will also apply
to H.266.
2021-01-21 17:13:54 +00:00
Nuo Mi 71de4ebede avcodec/cbs_h265: fix undef SEI_TYPE_X
Signed-off-by: James Almer <jamrial@gmail.com>
2021-01-11 17:03:15 -03:00
James Almer d1c55fc460 avcodec/cbs_h265: set default VUI parameters when vui_parameters_present_flag is false
Based on cbs_h264 code.

Should fix ticket #8752.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-25 23:36:12 -03:00
Martin Storsjö 1f7c8d319b cbs_h265: Fix use of an uninitialized variable
This fixes test failures in fate-cbs-hevc-* in certain configurations
since c53f9f4364.

Signed-off-by: Martin Storsjö <martin@martin.st>
2020-05-22 21:01:29 +03:00
Michael Niedermayer 435fa373d1 avcodec/cbs_h265_syntax_template: Limit num_long_term_pics more strictly
The limit is based on hevcdec.c
Fixes: 20854/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-5160442882424832
Fixes: out of array access

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-05-21 09:31:08 +02:00
Mark Thompson c53f9f4364 cbs_h265: Ensure that a predicted RPS doesn't contain too many pictures
If the RPS we are predicting from has maximum size then at least one of
the pictures in it must be discarded before adding the current one.

Also revert 588114cea4, which added
now-redundant checks for the special case of a too-large RPS with all
pictures being in the same direction from the current one.
2020-05-20 22:07:01 +01:00
James Almer 3d51d3b42d avcodec/cbs_h265: add missing support for reserved_payload_extension_data SEI bits
Fixes ticket #8622

Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-03 19:53:01 -03:00
James Almer 3a41bac4e2 avcodec/cbs_h265: move the payload_extension_present check into its own function
Will be reused in the following patch.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-03 19:53:01 -03:00
James Almer bdfc1d3cd3 avcodec/cbs_h265: rename H265RawPSExtensionData to H265RawExtensionData
So that NAL types other than Parameter Set ones may use it.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-03 19:53:00 -03:00
James Almer 38d1815cc6 avcodec/cbs_h265: fix writing extension_data bits
We only care about the right most bit.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-04-30 16:28:01 -03:00
Michael Niedermayer 588114cea4 avcodec/cbs_h265_syntax_template: Check num_negative/positive_pics when inter_ref_pic_set_prediction_flag is set
Fixes: out of array access
Fixes: 20446/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-5707770718584832

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-04-26 18:25:53 +02:00
Andreas Rheinhardt 7272d0c0a9 avcodec/hevc, h2645_parse: Fix HEVC NAL unit names and constants
This commit fixes the names and constants of the reserved NAL units
with nal_unit_type 22 resp. 23. They were "IRAP_IRAP_VLC2x", but are
actually "RSV_IRAP_VLC2x".

This also required a change to cbs_h265_syntax_template.c.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-24 23:33:24 +01:00
Andriy Gelman c07a772473 lavc/cbs_h2645_syntax_template: Fix memleak
payload_count is used to track the number of SEI payloads. It is also
used to free the SEIs in cbs_h264_free_sei()/cbs_h265_free_sei().

Currently, payload_count is set after for loop is completed. Hence if
there is an error and the function exits, the payload remains zero
causing a memleak.

This commit keeps track of payload_count inside the for loop to fix the
issue. Note that that the contents of current are initialized with
av_mallocz() so there is no need to zero initialize payload_count.

Found-by: libFuzzer
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2019-12-16 12:04:45 -03:00
James Almer e460dcc832 avcodec/cbs_h265: add support for Alpha Channel Info SEI messages
As defined in sections F.14.2.8 and F.14.3.8

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-07-20 11:28:09 -03:00
James Almer 45048ece81 avcodec/cbs_h2645: use the fixed() macro for forbidden_zero_bit
This follows the spec definition, and removes a field from the relevant
structs.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-04-28 20:29:40 -03:00
James Almer 16c50abb50 avcodec/cbs_h2645: add macros to read and write fields with no custom range of values
Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-04-28 20:28:42 -03:00
James Almer 137c0fcad1 avcodec/cbs_h265: fix storage type for time_offset_value in Time Code SEI
The spec defines it as an array of signed values, inferred to 0 when not
present.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-04-16 20:33:10 -03:00
Andreas Rheinhardt 9f588ba5ca cbs_h265: Fix Time Code SEI syntax
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
Signed-off-by: Mark Thompson <sw@jkqxz.net>
2018-12-02 19:49:08 +00:00
Mark Thompson 7a20656474 cbs_h265: Add a lot more SEI parsing support
Supports both prefix and suffix SEI, decoding all of the common SEI
types and some more obscure ones.  Most of this is tested by the
existing tests in fate.
2018-11-18 17:33:26 +00:00
Mark Thompson 252e79663d cbs_h265: Add PTL parsing for sublayers
With fate test using the SLPPLP_A_VIDYO_2 conformance file, which contains
two sublayers with full PTL information.
2018-11-11 17:22:09 +00:00
Mark Thompson 2dee0679e9 cbs_h265: Add PTL parsing for Main 10 Still Picture profile
This was added in the 2018 version of the standard.
2018-10-31 21:38:33 +00:00
Haihao Xiang 2943dd35b7 cbs_h265: read/write content light level information SEI message
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2018-05-10 20:55:42 +01:00
Haihao Xiang 56ed011692 cbs_h265: read/write HEVC PREFIX SEI
Similar to H264, cbs_h265_{read, write}_nal_unit() can handle HEVC
prefix SEI NAL units. Currently mastering display colour volume SEI
message is added only, we may add more SEI message if needed later

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2018-05-10 20:36:45 +01:00
Mark Thompson 300ef25314 cbs: Add support for array subscripts in trace output
This makes the trace output for arrays significantly nicer.
2018-05-02 01:20:45 +01:00
Mark Thompson 315cc8c098 cbs_h2645: Simplify representation of fixed values 2018-05-01 23:31:41 +01:00
Mark Thompson c4eeea7633 cbs_h265: Use helper macro for maximum values of fixed-width elements
Apply the same logic as the previous patch to H.265.  There are no cases
which currently overflow here, but this is still more consistent.
2018-03-18 17:55:00 +00:00
Mark Thompson 9b0c7aa0e4 lavc: Add coded bitstream read/write support for H.265
(cherry picked from commit 867381b8b5)
(cherry picked from commit f763489364)
(cherry picked from commit 067a9ddeb8)
2017-10-17 20:56:29 +01:00