History

lavc/vvc: Error if SPS ID is duplicated within CVS

Key line from the spec is: "All SPS NAL units with a particular value of sps_seq_parameter_set_id in a CVS shall have the same content." Prior to this patch, the VVC decoder's behaviour on encountering a duplicated SPS ID (within the entire bitstream, not restricted to a CVS) was simply to replace the entry in the SPS lookup table with the new data. Illegal bitstreams with multiple SPSs in the same CVS sharing an ID but differing elsewhere could cause all manner of issues. The patch tracks which SPS IDs have been used in the given CVS using the new sps_id_used field of VVCParamSets. If it encounters an SPS with an ID already in use and whose content differs from the previous SPS, it throws an AVERROR_INVALIDDATA.

Frank Plowman committed 2 years ago

Commit 2d79ae31 parent 0dbf4512 files · +23 −8Browse files

Unified · Split

2 files
  1. libavcodec/vvc/ps.c +20 −8
  2. libavcodec/vvc/ps.h +3 −0
libavcodec/vvc/ps.c+20−8
@@ -219,14 +219,22 @@ fail: · 218 unmodified lines
219219 return NULL;
220220 }
221221
222−static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx)
222+static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx, int is_clvss)
223223 {
224224 const int sps_id = rsps->sps_seq_parameter_set_id;
225225 const VVCSPS *old_sps = ps->sps_list[sps_id];
226226 const VVCSPS *sps;
227227
228− if (old_sps && old_sps->r == rsps)
229− return 0;
228+ if (is_clvss) {
229+ ps->sps_id_used = 0;
230+ }
231+
232+ if (old_sps) {
233+ if (old_sps->r == rsps || !memcmp(old_sps->r, rsps, sizeof(*old_sps->r)))
234+ return 0;
235+ else if (ps->sps_id_used & (1 << sps_id))
236+ return AVERROR_INVALIDDATA;
237+ }
230238
231239 sps = sps_alloc(rsps, log_ctx);
232240 if (!sps)
@@ -234,6 +242,7 @@ static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx) · 1 unmodified line
234242
235243 ff_refstruct_unref(&ps->sps_list[sps_id]);
236244 ps->sps_list[sps_id] = sps;
245+ ps->sps_id_used |= (1 << sps_id);
237246
238247 return 0;
239248 }
@@ -610,7 +619,7 @@ static int decode_pps(VVCParamSets *ps, const H266RawPPS *rpps) · 370 unmodified lines
610619 return ret;
611620 }
612621
613−static int decode_ps(VVCParamSets *ps, const CodedBitstreamH266Context *h266, void *log_ctx)
622+static int decode_ps(VVCParamSets *ps, const CodedBitstreamH266Context *h266, void *log_ctx, int is_clvss)
614623 {
615624 const H266RawPictureHeader *ph = h266->ph;
616625 const H266RawPPS *rpps;
@@ -628,7 +637,7 @@ static int decode_ps(VVCParamSets *ps, const CodedBitstreamH266Context *h266, vo · 11 unmodified lines
628637 if (!rsps)
629638 return AVERROR_INVALIDDATA;
630639
631− ret = decode_sps(ps, rsps, log_ctx);
640+ ret = decode_sps(ps, rsps, log_ctx, is_clvss);
632641 if (ret < 0)
633642 return ret;
634643
@@ -867,13 +876,16 @@ int ff_vvc_decode_frame_ps(VVCFrameParamSets *fps, struct VVCContext *s) · 232 unmodified lines
867876 int ret = 0;
868877 VVCParamSets *ps = &s->ps;
869878 const CodedBitstreamH266Context *h266 = s->cbc->priv_data;
879+ int is_clvss;
880+
881+ decode_recovery_flag(s);
882+ is_clvss = IS_CLVSS(s);
870883
871− ret = decode_ps(ps, h266, s->avctx);
884+ ret = decode_ps(ps, h266, s->avctx, is_clvss);
872885 if (ret < 0)
873886 return ret;
874887
875− decode_recovery_flag(s);
876− ret = decode_frame_ps(fps, ps, h266, s->poc_tid0, IS_CLVSS(s));
888+ ret = decode_frame_ps(fps, ps, h266, s->poc_tid0, is_clvss);
877889 decode_recovery_poc(s, &fps->ph);
878890 return ret;
879891 }
libavcodec/vvc/ps.h+3−0
@@ -214,6 +214,9 @@ typedef struct VVCParamSets { · 213 unmodified lines
214214 const VVCALF *alf_list[VVC_MAX_ALF_COUNT]; ///< RefStruct reference
215215 const H266RawAPS *lmcs_list[VVC_MAX_LMCS_COUNT]; ///< RefStruct reference
216216 const VVCScalingList *scaling_list[VVC_MAX_SL_COUNT]; ///< RefStruct reference
217+
218+ // Bit field of SPS IDs used in the current CVS
219+ uint16_t sps_id_used;
217220 } VVCParamSets;
218221
219222 typedef struct VVCFrameParamSets {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t