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

James Almer jamrial at gmail.com
Sun Apr 11 21:54:28 EEST 2021


On 4/10/2021 10:21 PM, Andreas Rheinhardt wrote:
> James Almer:
>> 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.
>>
> 
> Actually I intentionally didn't do that because the seek might work even
> when said flag is not set (when the destination is still in the
> AVIOContext's buffer).

Ok, patch LGTM then.

Carl argued this value should not be set in webp_write_trailer() to 
begin with, but that's a separate change.

> 
>>> +                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);
>>>        }
>>>
>>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
> 



More information about the ffmpeg-devel mailing list