[FFmpeg-devel,v2] avcodec/hevc_ps: Remove dead code in vps_id check

Submitted by Andriy Gelman on Sept. 22, 2019, 4:17 a.m.

Details

Message ID 20190922041729.6778-1-andriy.gelman@gmail.com
State Accepted
Commit 80e1c93c87f12e8ad8a2a37b0976204fddeaccc5
Headers show

Commit Message

Andriy Gelman Sept. 22, 2019, 4:17 a.m.
From: Andriy Gelman <andriy.gelman@gmail.com>

Since reading 4 bits always returns a value in the range [0, 15], the
check for vps_id >= HEVC_MAX_VPS_COUNT, where HEVC_MAX_VPS_COUNT = 16, is redundant.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
---
 libavcodec/hevc_ps.c | 8 --------
 1 file changed, 8 deletions(-)

Comments

Andriy Gelman Sept. 26, 2019, 11:48 a.m.
On Sun, 22. Sep 00:17, Andriy Gelman wrote:
> From: Andriy Gelman <andriy.gelman@gmail.com>
> 
> Since reading 4 bits always returns a value in the range [0, 15], the
> check for vps_id >= HEVC_MAX_VPS_COUNT, where HEVC_MAX_VPS_COUNT = 16, is redundant.
> 
> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
> ---
>  libavcodec/hevc_ps.c | 8 --------
>  1 file changed, 8 deletions(-)
> 
> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
> index abf08b919b..a30b8b8022 100644
> --- a/libavcodec/hevc_ps.c
> +++ b/libavcodec/hevc_ps.c
> @@ -448,10 +448,6 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>      memcpy(vps->data, gb->buffer, vps->data_size);
>  
>      vps_id = get_bits(gb, 4);
> -    if (vps_id >= HEVC_MAX_VPS_COUNT) {
> -        av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", vps_id);
> -        goto err;
> -    }
>  
>      if (get_bits(gb, 2) != 3) { // vps_reserved_three_2bits
>          av_log(avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n");
> @@ -883,10 +879,6 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
>      // Coded parameters
>  
>      sps->vps_id = get_bits(gb, 4);
> -    if (sps->vps_id >= HEVC_MAX_VPS_COUNT) {
> -        av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", sps->vps_id);
> -        return AVERROR_INVALIDDATA;
> -    }
>  
>      if (vps_list && !vps_list[sps->vps_id]) {
>          av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
> -- 
> 2.23.0
> 

ping
James Almer Sept. 26, 2019, 2:21 p.m.
On 9/26/2019 8:48 AM, Andriy Gelman wrote:
> On Sun, 22. Sep 00:17, Andriy Gelman wrote:
>> From: Andriy Gelman <andriy.gelman@gmail.com>
>>
>> Since reading 4 bits always returns a value in the range [0, 15], the
>> check for vps_id >= HEVC_MAX_VPS_COUNT, where HEVC_MAX_VPS_COUNT = 16, is redundant.
>>
>> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
>> ---
>>  libavcodec/hevc_ps.c | 8 --------
>>  1 file changed, 8 deletions(-)
>>
>> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
>> index abf08b919b..a30b8b8022 100644
>> --- a/libavcodec/hevc_ps.c
>> +++ b/libavcodec/hevc_ps.c
>> @@ -448,10 +448,6 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>>      memcpy(vps->data, gb->buffer, vps->data_size);
>>  
>>      vps_id = get_bits(gb, 4);
>> -    if (vps_id >= HEVC_MAX_VPS_COUNT) {
>> -        av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", vps_id);
>> -        goto err;
>> -    }
>>  
>>      if (get_bits(gb, 2) != 3) { // vps_reserved_three_2bits
>>          av_log(avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n");
>> @@ -883,10 +879,6 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
>>      // Coded parameters
>>  
>>      sps->vps_id = get_bits(gb, 4);
>> -    if (sps->vps_id >= HEVC_MAX_VPS_COUNT) {
>> -        av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", sps->vps_id);
>> -        return AVERROR_INVALIDDATA;
>> -    }
>>  
>>      if (vps_list && !vps_list[sps->vps_id]) {
>>          av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
>> -- 
>> 2.23.0
>>
> 
> ping

Applied, thanks.

Patch hide | download patch | download mbox

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index abf08b919b..a30b8b8022 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -448,10 +448,6 @@  int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
     memcpy(vps->data, gb->buffer, vps->data_size);
 
     vps_id = get_bits(gb, 4);
-    if (vps_id >= HEVC_MAX_VPS_COUNT) {
-        av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", vps_id);
-        goto err;
-    }
 
     if (get_bits(gb, 2) != 3) { // vps_reserved_three_2bits
         av_log(avctx, AV_LOG_ERROR, "vps_reserved_three_2bits is not three\n");
@@ -883,10 +879,6 @@  int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
     // Coded parameters
 
     sps->vps_id = get_bits(gb, 4);
-    if (sps->vps_id >= HEVC_MAX_VPS_COUNT) {
-        av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", sps->vps_id);
-        return AVERROR_INVALIDDATA;
-    }
 
     if (vps_list && !vps_list[sps->vps_id]) {
         av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",