Hi,

On Mon, Jan 9, 2012 at 1:50 PM, Aneesh Dogra <[email protected]> wrote:
> +static int get_nb_samples(AVCodecContext *avctx, GetByteContext *g,
> +                          int *coded_samples)
>  {
>     ADPCMDecodeContext *s = avctx->priv_data;

Add GetByteContext to ADPCMDecodeContext, so we don't need extra
function arguments.

>     int nb_samples        = 0;
>     int ch                = avctx->channels;
>     int has_coded_samples = 0;
>     int header_size;
> +    int buf_size          = bytestream2_get_bytes_left(g);

Why do you need to know buf_size here? Ideally all these buf_size
checks can now disappear.

> -            if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be 
> null but is %d!!\n", src[-1]); /* unused */
> +            if (bytestream2_peek_byte(&g))
> +                av_log(avctx, AV_LOG_ERROR,
> +                       "unused byte should be null but is %d!!\n",
> +                       bytestream2_peek_byte(&g)); /* unused */
> +            bytestream2_skip(&g, 1);
>         }

unsigned int tmp = bytestream2_get_byte(&g);
if (tmp)
    av_log(.., "Bla is not null: %d\n", tmp);

> -    case CODEC_ID_ADPCM_XA:
> -        while (buf_size >= 128) {
> -            xa_decode(samples, src, &c->status[0], &c->status[1],
> +    case CODEC_ID_ADPCM_XA: {
> +        unsigned char buffer[128];
> +        while (bytestream2_get_bytes_left(&g) >= 128) {
> +            bytestream2_get_buffer(&g, buffer, 128);
> +            xa_decode(samples, buffer, &c->status[0], &c->status[1],
>                 avctx->channels);
> -            src += 128;
>             samples += 28 * 8;
>             buf_size -= 128;
>         }
>         break;

No. xa_decode() is now still vulnerable to overreads.

>                     for (count2=0; count2<28; count2++) {
>                         if (count2 & 1)
> -                            next_sample = sign_extend(*srcC++,    4) << 
> shift;
> +                            next_sample = 
> sign_extend(bytestream2_get_byte(&g),    4) << shift;
>                         else
> -                            next_sample = sign_extend(*srcC >> 4, 4) << 
> shift;
> +                            next_sample = 
> sign_extend(bytestream2_peek_byte(&g) >> 4, 4) << shift;

Unroll this:

for (count2 = 0; count2 < 14; count2++) {
    unsigned int tmp = bytestream2_get_byte();
    next_sample = .. & 0xf;
    ..
    next_sample = .. >> 4;
    ..
}

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

Reply via email to