[FFmpeg-devel] [PATCH] avcodec/libmp3lame: properly handle unaligned frame data

Michael Niedermayer michael at niedermayer.cc
Wed Apr 26 16:46:08 EEST 2017


On Wed, Apr 26, 2017 at 05:16:05PM +0700, Muhammad Faiz wrote:
> This should fix Ticket6349
> 
> Since 383057f8e744efeaaa3648a59bc577b25b055835, framequeue may
> generate unaligned frame data.
> 
> Signed-off-by: Muhammad Faiz <mfcc64 at gmail.com>
> ---
>  libavcodec/libmp3lame.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
> index 5e26743..cd505bb 100644
> --- a/libavcodec/libmp3lame.c
> +++ b/libavcodec/libmp3lame.c
> @@ -203,15 +203,20 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>              ENCODE_BUFFER(lame_encode_buffer_int, int32_t, frame->data);
>              break;
>          case AV_SAMPLE_FMT_FLTP:
> -            if (frame->linesize[0] < 4 * FFALIGN(frame->nb_samples, 8)) {
> -                av_log(avctx, AV_LOG_ERROR, "inadequate AVFrame plane padding\n");
> -                return AVERROR(EINVAL);
> -            }
>              for (ch = 0; ch < avctx->channels; ch++) {
> +                if (frame->linesize[0] < 4 * FFALIGN(frame->nb_samples, 8) || 0x1F & (intptr_t)(frame->data[ch])) {
> +                    float *src = (float *) frame->data[ch];
> +                    float *dst = s->samples_flt[ch];
> +                    int k;
> +
> +                    for (k = 0; k < frame->nb_samples; k++)
> +                        dst[k] = src[k] * 32768.0f;

If this solution is choosen then
this should produce a one time log message to inform about
the sub optimal alignment

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Never trust a computer, one day, it may think you are the virus. -- Compn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170426/71909061/attachment.sig>


More information about the ffmpeg-devel mailing list