From bf7f0f45863b46b7594f8c8b0a8dd3d22de99666 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Mon, 20 Nov 2023 17:23:26 +0100 Subject: [PATCH] fix access to non-existent reference picture (#429) --- libde265/motion.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libde265/motion.cc b/libde265/motion.cc index 4a8fb135..f85dc90e 100644 --- a/libde265/motion.cc +++ b/libde265/motion.cc @@ -1717,8 +1717,15 @@ void derive_spatial_luma_vector_prediction(base_context* ctx, const de265_image* imgX = NULL; if (vi.predFlag[X]) imgX = ctx->get_image(shdr->RefPicList[X][ vi.refIdx[X] ]); + const de265_image* imgY = NULL; - if (vi.predFlag[Y]) imgY = ctx->get_image(shdr->RefPicList[Y][ vi.refIdx[Y] ]); + if (vi.predFlag[Y]) { + // check for input data validity + if (vi.refIdx[Y]<0 || vi.refIdx[Y] >= MAX_NUM_REF_PICS) + return; + + imgY = ctx->get_image(shdr->RefPicList[Y][ vi.refIdx[Y] ]); + } // check whether the predictor X is available and references the same POC if (vi.predFlag[X] && imgX && imgX->PicOrderCntVal == referenced_POC) { @@ -1848,6 +1855,10 @@ void derive_spatial_luma_vector_prediction(base_context* ctx, logtrace(LogMotion,"MVP B%d=\n",k); logmvcand(vi); + if (vi.refIdx[Y] < 0 || vi.refIdx[Y] >= MAX_NUM_REF_PICS) { + return; + } + const de265_image* imgX = NULL; if (vi.predFlag[X]) imgX = ctx->get_image(shdr->RefPicList[X][ vi.refIdx[X] ]); const de265_image* imgY = NULL;