diff mbox series

[FFmpeg-devel,2/3] avcodec/mlpdec: Use get_bits() instead of get_bits_long() when possible

Message ID AM7PR03MB6660F9B8662C7DBB75B266658F4B9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Withdrawn
Headers show
Series [FFmpeg-devel,1/3] avformat/takdec: Don't initialize get_bits context to read one value | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 5, 2022, 9:38 p.m. UTC
huff_lsbs is guaranteed to be in the range of 0..24 and
so is lsb_bits here, so one can use get_bits().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mlpdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Niedermayer Jan. 6, 2022, 9:32 a.m. UTC | #1
On Wed, Jan 05, 2022 at 10:38:34PM +0100, Andreas Rheinhardt wrote:
> huff_lsbs is guaranteed to be in the range of 0..24 and
> so is lsb_bits here, so one can use get_bits().
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/mlpdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
> index 29fac54542..61b9a641dd 100644
> --- a/libavcodec/mlpdec.c
> +++ b/libavcodec/mlpdec.c
> @@ -268,7 +268,7 @@ static inline int read_huff_channels(MLPDecodeContext *m, GetBitContext *gbp,
>              return AVERROR_INVALIDDATA;
>  
>          if (lsb_bits > 0)
> -            result = (result << lsb_bits) + get_bits_long(gbp, lsb_bits);
> +            result = (result << lsb_bits) + get_bits(gbp, lsb_bits);
>  
>          result  += cp->sign_huff_offset;
>          result *= 1 << quant_step_size;

This seems not to fully work

Assertion n>0 && n<=25 failed at libavcodec/get_bits.h:403

lsb_bits and cp->huff_lsbs are 31 in this failure, it seems
the checks that prevent this are conditional but i didnt debug/check this
any further

thx

[...]
Andreas Rheinhardt Jan. 6, 2022, 9:35 a.m. UTC | #2
Michael Niedermayer:
> On Wed, Jan 05, 2022 at 10:38:34PM +0100, Andreas Rheinhardt wrote:
>> huff_lsbs is guaranteed to be in the range of 0..24 and
>> so is lsb_bits here, so one can use get_bits().
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/mlpdec.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
>> index 29fac54542..61b9a641dd 100644
>> --- a/libavcodec/mlpdec.c
>> +++ b/libavcodec/mlpdec.c
>> @@ -268,7 +268,7 @@ static inline int read_huff_channels(MLPDecodeContext *m, GetBitContext *gbp,
>>              return AVERROR_INVALIDDATA;
>>  
>>          if (lsb_bits > 0)
>> -            result = (result << lsb_bits) + get_bits_long(gbp, lsb_bits);
>> +            result = (result << lsb_bits) + get_bits(gbp, lsb_bits);
>>  
>>          result  += cp->sign_huff_offset;
>>          result *= 1 << quant_step_size;
> 
> This seems not to fully work
> 
> Assertion n>0 && n<=25 failed at libavcodec/get_bits.h:403
> 
> lsb_bits and cp->huff_lsbs are 31 in this failure, it seems
> the checks that prevent this are conditional but i didnt debug/check this
> any further
> 

Seems like I misread the check at line 841: It does not apply to the
first codebook: if (cp->codebook > 0 && cp->huff_lsbs > 24) {
Thanks for testing, patch dropped.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 29fac54542..61b9a641dd 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -268,7 +268,7 @@  static inline int read_huff_channels(MLPDecodeContext *m, GetBitContext *gbp,
             return AVERROR_INVALIDDATA;
 
         if (lsb_bits > 0)
-            result = (result << lsb_bits) + get_bits_long(gbp, lsb_bits);
+            result = (result << lsb_bits) + get_bits(gbp, lsb_bits);
 
         result  += cp->sign_huff_offset;
         result *= 1 << quant_step_size;