From 1c61c24f5f681c573afce2fba804962e88ca262a Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Mon, 10 Jul 2023 16:35:17 +0800 Subject: [PATCH] vulkan/hevc: handle missing active PPS I don't pretend to understand how we get into this situation, but there are files out there where we can end up with the active PPS not being identified when we call vk_hevc_end_frame. In these situations today, we will segfault. So, before we give up, see if we can get the active PPS id from the slice header, and use that if possible. If that still doesn't work, return an error instead of segfaulting. --- libavcodec/vulkan_hevc.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c index af5da3984b..ab0f6b96d0 100644 --- a/libavcodec/vulkan_hevc.c +++ b/libavcodec/vulkan_hevc.c @@ -900,6 +900,7 @@ static int vk_hevc_end_frame(AVCodecContext *avctx) FFVulkanDecodePicture *vp = &hp->vp; FFVulkanDecodePicture *rvp[HEVC_MAX_REFS] = { 0 }; AVFrame *rav[HEVC_MAX_REFS] = { 0 }; + int err; if (!hp->h265_pic_info.sliceSegmentCount) return 0; @@ -908,7 +909,19 @@ static int vk_hevc_end_frame(AVCodecContext *avctx) const HEVCSPS *sps = h->ps.sps; const HEVCPPS *pps = h->ps.pps; - int err = vk_hevc_create_params(avctx, &dec->session_params); + if (!pps) { + unsigned int pps_id = h->sh.pps_id; + if (pps_id < HEVC_MAX_PPS_COUNT && h->ps.pps_list[pps_id] != NULL) + pps = (const HEVCPPS *)h->ps.pps_list[pps_id]->data; + } + + if (!pps) { + av_log(avctx, AV_LOG_ERROR, + "Encountered frame without a valid active PPS reference.\n"); + return AVERROR_INVALIDDATA; + } + + err = vk_hevc_create_params(avctx, &dec->session_params); if (err < 0) return err;