[FFmpeg-devel] [PATCH] misc libvorbis.c fixes

David Conrad lessen42
Sat Jul 3 09:35:29 CEST 2010


Sorry for the delays...

On Jun 29, 2010, at 3:44 AM, Pascal Massimino wrote:

> Index: libavcodec/libvorbis.c
> ===================================================================
> --- libavcodec/libvorbis.c	(revision 23816)
> +++ libavcodec/libvorbis.c	(working copy)
> @@ -84,11 +84,14 @@
>      return vorbis_encode_setup_init(vi);
>  }
>  
> +/* How many bytes are needed for a buffer of length 'l' */
> +static int xiph_len(int l) { return (1 + l / 255 + l); }
> +
>  static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) {
>      OggVorbisContext *context = avccontext->priv_data ;
>      ogg_packet header, header_comm, header_code;
>      uint8_t *p;
> -    unsigned int offset, len;
> +    unsigned int offset;
>  
>      vorbis_info_init(&context->vi) ;
>      if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) {
> @@ -104,9 +107,10 @@
>      vorbis_analysis_headerout(&context->vd, &context->vc, &header,
>                                  &header_comm, &header_code);
>  
> -    len = header.bytes + header_comm.bytes +  header_code.bytes;
> -    avccontext->extradata_size= 64 + len + len/255;
> -    p = avccontext->extradata= av_mallocz(avccontext->extradata_size);
> +    avccontext->extradata_size=
> +        1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) +
> +        header_code.bytes;
> +    p = avccontext->extradata = av_malloc(avccontext->extradata_size);

Might as well add in the missing FF_INPUT_BUFFER_PADDING_SIZE while you're at it

>      p[0] = 2;
>      offset = 1;
>      offset += av_xiphlacing(&p[offset], header.bytes);
> @@ -117,8 +121,7 @@
>      offset += header_comm.bytes;
>      memcpy(&p[offset], header_code.packet, header_code.bytes);
>      offset += header_code.bytes;
> -    avccontext->extradata_size = offset;
> -    avccontext->extradata= av_realloc(avccontext->extradata, avccontext->extradata_size);
> +    assert(offset == avccontext->extradata_size);

Which makes this assert invalid, but it should probably go anyway.

>  /*    vorbis_block_clear(&context->vb);
>      vorbis_dsp_clear(&context->vd);

OK with those changes, and other 2 patches are OK too.



More information about the ffmpeg-devel mailing list