* [FFmpeg-devel] [PATCH] avcodec/hevc_ps: add proper bound checks around cm_ref_layer_id in colour_mapping_table.
@ 2023-05-17 17:28 Michael Niedermayer
2023-05-17 20:32 ` James Almer
0 siblings, 1 reply; 2+ messages in thread
From: Michael Niedermayer @ 2023-05-17 17:28 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Clement Lecigne
From: Clement Lecigne <clecigne@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavcodec/hevc_ps.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index a55bced0f7..313ebef151 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1374,9 +1374,14 @@ static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_dept
}
}
-static void colour_mapping_table(GetBitContext *gb, HEVCPPS *pps)
+static int colour_mapping_table(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps)
{
- pps->num_cm_ref_layers_minus1 = get_ue_golomb_long(gb);
+ pps->num_cm_ref_layers_minus1 = get_ue_golomb(gb);
+ if (pps->num_cm_ref_layers_minus1 >= 63U) {
+ av_log(avctx, AV_LOG_ERROR,
+ "num_cm_ref_layers_minus1 shall be in the range [0, 63].\n");
+ return AVERROR_INVALIDDATA;
+ }
for (int i = 0; i <= pps->num_cm_ref_layers_minus1; i++)
pps->cm_ref_layer_id[i] = get_bits(gb, 6);
@@ -1397,6 +1402,7 @@ static void colour_mapping_table(GetBitContext *gb, HEVCPPS *pps)
}
colour_mapping_octants(gb, pps, 0, 0, 0, 0, 1 << pps->cm_octant_depth);
+ return 0;
}
static int pps_multilayer_extension(GetBitContext *gb, AVCodecContext *avctx,
@@ -1439,8 +1445,11 @@ static int pps_multilayer_extension(GetBitContext *gb, AVCodecContext *avctx,
}
pps->colour_mapping_enabled_flag = get_bits1(gb);
- if (pps->colour_mapping_enabled_flag)
- colour_mapping_table(gb, pps);
+ if (pps->colour_mapping_enabled_flag) {
+ int ret = colour_mapping_table(gb, avctx, pps);
+ if (ret < 0)
+ return ret;
+ }
return 0;
}
--
2.17.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: add proper bound checks around cm_ref_layer_id in colour_mapping_table.
2023-05-17 17:28 [FFmpeg-devel] [PATCH] avcodec/hevc_ps: add proper bound checks around cm_ref_layer_id in colour_mapping_table Michael Niedermayer
@ 2023-05-17 20:32 ` James Almer
0 siblings, 0 replies; 2+ messages in thread
From: James Almer @ 2023-05-17 20:32 UTC (permalink / raw)
To: ffmpeg-devel
On 5/17/2023 2:28 PM, Michael Niedermayer wrote:
> From: Clement Lecigne <clecigne@google.com>
>
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
> libavcodec/hevc_ps.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
> index a55bced0f7..313ebef151 100644
> --- a/libavcodec/hevc_ps.c
> +++ b/libavcodec/hevc_ps.c
> @@ -1374,9 +1374,14 @@ static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_dept
> }
> }
>
> -static void colour_mapping_table(GetBitContext *gb, HEVCPPS *pps)
> +static int colour_mapping_table(GetBitContext *gb, AVCodecContext *avctx, HEVCPPS *pps)
> {
> - pps->num_cm_ref_layers_minus1 = get_ue_golomb_long(gb);
> + pps->num_cm_ref_layers_minus1 = get_ue_golomb(gb);
> + if (pps->num_cm_ref_layers_minus1 >= 63U) {
> + av_log(avctx, AV_LOG_ERROR,
> + "num_cm_ref_layers_minus1 shall be in the range [0, 63].\n");
The spec in section F.7.4.3.3.5 says 0..61, no 0..63.
I'll amend this (and update the array in the struct while at it) and push.
> + return AVERROR_INVALIDDATA;
> + }
> for (int i = 0; i <= pps->num_cm_ref_layers_minus1; i++)
> pps->cm_ref_layer_id[i] = get_bits(gb, 6);
>
> @@ -1397,6 +1402,7 @@ static void colour_mapping_table(GetBitContext *gb, HEVCPPS *pps)
> }
>
> colour_mapping_octants(gb, pps, 0, 0, 0, 0, 1 << pps->cm_octant_depth);
> + return 0;
> }
>
> static int pps_multilayer_extension(GetBitContext *gb, AVCodecContext *avctx,
> @@ -1439,8 +1445,11 @@ static int pps_multilayer_extension(GetBitContext *gb, AVCodecContext *avctx,
> }
>
> pps->colour_mapping_enabled_flag = get_bits1(gb);
> - if (pps->colour_mapping_enabled_flag)
> - colour_mapping_table(gb, pps);
> + if (pps->colour_mapping_enabled_flag) {
> + int ret = colour_mapping_table(gb, avctx, pps);
> + if (ret < 0)
> + return ret;
> + }
>
> return 0;
> }
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-17 20:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-17 17:28 [FFmpeg-devel] [PATCH] avcodec/hevc_ps: add proper bound checks around cm_ref_layer_id in colour_mapping_table Michael Niedermayer
2023-05-17 20:32 ` James Almer
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git