aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorFrank Plowman <post@frankplowman.com>2024-06-14 10:37:17 +0100
committerNuo Mi <nuomi2021@gmail.com>2024-06-20 20:33:23 +0800
commit8d6014dbc6fb7c324a114030761901220ebc3540 (patch)
tree7a384c24b6cb138dd25f885388cb028d691a6ee5 /libavcodec
parent02430680b02ee42472148e67e178b6d1c2ac43fd (diff)
downloadffmpeg-8d6014dbc6fb7c324a114030761901220ebc3540.tar.gz
lavc/vvc: Invalidate PPSs which refer to a changed SPS
When the SPS associated with a particular SPS ID changes, invalidate all the PPSs which use that SPS ID. Fixes crashes with illegal bitstreams. This is done in the CBS, rather than in libavcodec/vvc/ps.c like the SPS ID reuse validation, as parts of the CBS parsing process for PPSs depend on the SPS being referred to. Signed-off-by: Frank Plowman <post@frankplowman.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/cbs_h2645.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index c5f167334d..e2389f124e 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -789,9 +789,28 @@ static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
}
cbs_h266_replace_ps(6, VPS, vps, vps_video_parameter_set_id)
-cbs_h266_replace_ps(6, SPS, sps, sps_seq_parameter_set_id)
cbs_h266_replace_ps(6, PPS, pps, pps_pic_parameter_set_id)
+static int cbs_h266_replace_sps(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit)
+{
+ CodedBitstreamH266Context *priv = ctx->priv_data;
+ H266RawSPS *sps = unit->content;
+ unsigned int id = sps->sps_seq_parameter_set_id;
+ int err = ff_cbs_make_unit_refcounted(ctx, unit);
+ if (err < 0)
+ return err;
+ av_assert0(unit->content_ref);
+ if (priv->sps[id] && memcmp(priv->sps[id], unit->content_ref, sizeof(*priv->sps[id]))) {
+ for (unsigned int i = 0; i < VVC_MAX_PPS_COUNT; i++) {
+ if (priv->pps[i] && priv->pps[i]->pps_seq_parameter_set_id == id)
+ ff_refstruct_unref(&priv->pps[i]);
+ }
+ }
+ ff_refstruct_replace(&priv->sps[id], unit->content_ref);
+ return 0;
+}
+
static int cbs_h266_replace_ph(CodedBitstreamContext *ctx,
CodedBitstreamUnit *unit,
H266RawPictureHeader *ph)