The VPS referenced by the SPS must always be present as the max value for sps_max_sub_layers_minus1 is vps_max_sub_layers_minus1. This replaces a buggy custom range check for the aforementioned field. Also, add the missing conformance check for sps_temporal_id_nesting_flag while at it.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -788,25 +788,28 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, · 787 unmodified lines | ||
| 788 | 788 | |
| 789 | 789 | ub(4, sps_video_parameter_set_id); |
| 790 | 790 | h265->active_vps = vps = h265->vps[current->sps_video_parameter_set_id]; |
| 791 | + if (!vps) { | |
| 792 | + av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n", | |
| 793 | + current->sps_video_parameter_set_id); | |
| 794 | + return AVERROR_INVALIDDATA; | |
| 795 | + } | |
| 791 | 796 | |
| 792 | − u(3, sps_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS - 1); | |
| 797 | + u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1); | |
| 793 | 798 | flag(sps_temporal_id_nesting_flag); |
| 794 | − if (vps) { | |
| 795 | − if (vps->vps_max_sub_layers_minus1 > current->sps_max_sub_layers_minus1) { | |
| 796 | − av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " | |
| 797 | − "sps_max_sub_layers_minus1 (%d) must be less than or equal to " | |
| 798 | − "vps_max_sub_layers_minus1 (%d).\n", | |
| 799 | − vps->vps_max_sub_layers_minus1, | |
| 800 | − current->sps_max_sub_layers_minus1); | |
| 801 | − return AVERROR_INVALIDDATA; | |
| 802 | − } | |
| 803 | − if (vps->vps_temporal_id_nesting_flag && | |
| 804 | − !current->sps_temporal_id_nesting_flag) { | |
| 805 | − av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " | |
| 806 | − "sps_temporal_id_nesting_flag must be 1 if " | |
| 807 | − "vps_temporal_id_nesting_flag is 1.\n"); | |
| 808 | − return AVERROR_INVALIDDATA; | |
| 809 | − } | |
| 799 | + | |
| 800 | + if (vps->vps_temporal_id_nesting_flag && | |
| 801 | + !current->sps_temporal_id_nesting_flag) { | |
| 802 | + av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " | |
| 803 | + "sps_temporal_id_nesting_flag must be 1 if " | |
| 804 | + "vps_temporal_id_nesting_flag is 1.\n"); | |
| 805 | + return AVERROR_INVALIDDATA; | |
| 806 | + } | |
| 807 | + if (current->sps_max_sub_layers_minus1 == 0 && | |
| 808 | + current->sps_temporal_id_nesting_flag != 1) { | |
| 809 | + av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: " | |
| 810 | + "sps_temporal_id_nesting_flag must be 1 if " | |
| 811 | + "sps_max_sub_layers_minus1 is 0.\n"); | |
| 812 | + return AVERROR_INVALIDDATA; | |
| 810 | 813 | } |
| 811 | 814 | |
| 812 | 815 | CHECK(FUNC(profile_tier_level)(ctx, rw, ¤t->profile_tier_level, |