[FFmpeg-devel] [PATCH] Complain about and ignore obviously broken protocol size.
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sat Dec 31 19:19:13 CET 2011
On 31 Dec 2011, at 18:51, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Sat, Dec 31, 2011 at 06:07:23PM +0100, Reimar Döffinger wrote:
>> Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
>> ---
>> libavformat/utils.c | 10 +++++++---
>> 1 files changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/libavformat/utils.c b/libavformat/utils.c
>> index 517b852..9228821 100644
>> --- a/libavformat/utils.c
>> +++ b/libavformat/utils.c
>> @@ -270,11 +270,15 @@ AVInputFormat *av_find_input_format(const char *short_name)
>> int ffio_limit(AVIOContext *s, int size)
>> {
>> if(s->maxsize>=0){
>> - int64_t remaining= s->maxsize - avio_tell(s);
>> + int64_t pos = avio_tell(s);
>> + int64_t remaining= s->maxsize - pos;
>> if(remaining < size){
>> int64_t newsize= avio_size(s);
>> - if(!s->maxsize || s->maxsize<newsize)
>> - s->maxsize= newsize - !newsize;
>> + if(newsize >= 0 && newsize <= pos) {
>> + av_log(0, AV_LOG_ERROR, "Broken protocol implementation, size <= pos\n");
>
> i dont think avio_size() is guranteed to be more than the current
> position
Ok with < then?
Though it probably is a rare condition that ffio_limit will be called from EOF position.
In theory I think my variant might "break" if it is called at position 0 with a broken protocol, but I don't like assuming that avio_size indicates always necessarily an error, for example a file still being downloaded can have size 0 at the beginning and still become playable later (though if ffio_limit is called while it's still 0 things probably are already broken...).
More information about the ffmpeg-devel
mailing list