On 03/18/2012 02:02 PM, Ronald S. Bultje wrote:

> Hi,
> 
> On Sun, Mar 18, 2012 at 10:15 AM, Ronald S. Bultje <[email protected]> wrote:
>> ---
>>  libavcodec/adpcm.c |   30 +++++++++++++++++-------------
>>  1 files changed, 17 insertions(+), 13 deletions(-)
>>
>> diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
>> index 72e93f5..0891040 100644
>> --- a/libavcodec/adpcm.c
>> +++ b/libavcodec/adpcm.c
>> @@ -353,6 +353,7 @@ static int xa_decode(AVCodecContext *avctx,
>>  *                           number of samples in each frame.
>>  */
>>  static int get_nb_samples(AVCodecContext *avctx, const uint8_t *buf,
>> +                          GetByteContext *gb,
>>                           int buf_size, int *coded_samples)
>>  {
>>     ADPCMDecodeContext *s = avctx->priv_data;
>> @@ -410,9 +411,7 @@ static int get_nb_samples(AVCodecContext *avctx, const 
>> uint8_t *buf,
>>         break;
>>     case CODEC_ID_ADPCM_IMA_EA_EACS:
>>         has_coded_samples = 1;
>> -        if (buf_size < 4)
>> -            return 0;
>> -        *coded_samples = AV_RL32(buf);
>> +        *coded_samples = bytestream2_get_le32(gb);
>>         nb_samples     = (buf_size - (4 + 8 * ch)) * 2 / ch;
>>         break;
>>     case CODEC_ID_ADPCM_EA_MAXIS_XA:
>> @@ -529,7 +528,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, 
>> void *data,
>>     int nb_samples, coded_samples, ret;
>>     GetByteContext gb;
>>
>> -    nb_samples = get_nb_samples(avctx, buf, buf_size, &coded_samples);
>> +    bytestream2_init(&gb, buf, buf_size);
>> +    nb_samples = get_nb_samples(avctx, buf, &gb, buf_size, &coded_samples);
>>     if (nb_samples <= 0) {
>>         av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
>>         return AVERROR_INVALIDDATA;
>> @@ -552,7 +552,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx, 
>> void *data,
>>     }
>>
>>     src = buf;
>> -    bytestream2_init(&gb, buf, buf_size);
>>
>>     st = avctx->channels == 2 ? 1 : 0;
>>
>> @@ -842,16 +841,21 @@ static int adpcm_decode_frame(AVCodecContext *avctx, 
>> void *data,
>>         }
>>         break;
>>     case CODEC_ID_ADPCM_IMA_EA_EACS:
>> -        src += 4; // skip sample count (already read)
>> -
>> -        for (i=0; i<=st; i++)
>> -            c->status[i].step_index = av_clip(bytestream_get_le32(&src), 0, 
>> 88);
>> +        for (i=0; i<=st; i++) {
>> +            c->status[i].step_index = bytestream2_get_le32u(&gb);
>> +            if (c->status[i].step_index > 88u) {
>> +                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
>> +                       i, c->status[i].step_index);
>> +                return AVERROR_INVALIDDATA;
>> +            }
>> +        }
>>         for (i=0; i<=st; i++)
>> -            c->status[i].predictor  = bytestream_get_le32(&src);
>> +            c->status[i].predictor  = bytestream2_get_le32u(&gb);
> 
> General question, all code in this file lacks sign extensions for
> 32bit values, as happens here. Does sign_extend(x, 32) do anything
> useful? And what if int is not 32bit (that probably breaks all code in
> this file at least) - do we support that at all?


Using sign_extend() is really no better than casting in this case since
it takes a signed int as the input argument.  I think AV_WN32A() is the
correct thing to use here.

-Justin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to