[FFmpeg-devel] [PATCH 3/3] avformat/webpenc: Check seeks

James Almer jamrial at gmail.com
Sun Apr 11 04:18:31 EEST 2021


On 4/10/2021 9:43 PM, Andreas Rheinhardt wrote:
> When writing the trailer, the WebP muxer unconditionally seeks back
> to the front to update some elements. Yet this doesn't work if
> the seek failed, so check for this.
> 
> (This has been mentioned in ticket #9179.)
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> ---
>   libavformat/webpenc.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c
> index 3962986c32..a24920d181 100644
> --- a/libavformat/webpenc.c
> +++ b/libavformat/webpenc.c
> @@ -174,8 +174,8 @@ static int webp_write_trailer(AVFormatContext *s)
>   
>       if (w->using_webp_anim_encoder) {
>           if ((w->frame_count > 1) && w->loop) {  // Write loop count.
> -            avio_seek(s->pb, 42, SEEK_SET);
> -            avio_wl16(s->pb, w->loop);
> +            if (avio_seek(s->pb, 42, SEEK_SET) == 42)

I think it's better if you also check for (s->pb->seekable & 
AVIO_SEEKABLE_NORMAL) before calling avio_seek() + avio_w* to begin with.

> +                avio_wl16(s->pb, w->loop);
>           }
>       } else {
>           int ret;
> @@ -183,8 +183,8 @@ static int webp_write_trailer(AVFormatContext *s)
>               return ret;
>   
>           filesize = avio_tell(s->pb);
> -        avio_seek(s->pb, 4, SEEK_SET);
> -        avio_wl32(s->pb, filesize - 8);
> +        if (avio_seek(s->pb, 4, SEEK_SET) == 4)
> +            avio_wl32(s->pb, filesize - 8);
>           // Note: without the following, avio only writes 8 bytes to the file.
>           avio_seek(s->pb, filesize, SEEK_SET);
>       }
> 



More information about the ffmpeg-devel mailing list