[FFmpeg-devel] [PATCH] img2dec: Don't leave AVIOContexts open on zero byte files

Michael Niedermayer michaelni at gmx.at
Fri Sep 7 12:10:24 CEST 2012


On Fri, Sep 07, 2012 at 11:03:47AM +0200, Tomas Härdin wrote:
> Hi
> 
> The attached patch fixes img2dec leaving file descriptors/HTTP
> connections/etc. open if an image sequence contains a zero-sized file.
> 
> make fate ran fine.
> 
> I'm sending a slightly different patch to libav-devel since for some
> reason the demuxers look a bit different (s->split_planes vs
> codec->codec_id == AV_CODEC_ID_RAWVIDEO).
> 
> /Tomas

>  img2dec.c |   11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> c17c6e8a6f225faf7b84ac0e8b07998564a6480d  0001-img2dec-Don-t-leave-AVIOContexts-open-on-zero-byte-f.patch
> From 9f9dec52e9ebd5d01ccd340417af7de0fdb005a5 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <tomas.hardin at codemill.se>
> Date: Fri, 7 Sep 2012 10:16:15 +0200
> Subject: [PATCH] img2dec: Don't leave AVIOContexts open on zero byte files
> 
> ---
>  libavformat/img2dec.c |   11 ++++++-----
>  1 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
> index cc1faf8..7d0b2e5 100644
> --- a/libavformat/img2dec.c
> +++ b/libavformat/img2dec.c
> @@ -329,7 +329,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
>      char filename_bytes[1024];
>      char *filename = filename_bytes;
>      int i;
> -    int size[3]={0}, ret[3]={0};
> +    int size[3]={0}, ret[3]={-1,-1,-1};
>      AVIOContext *f[3];
>      AVCodecContext *codec= s1->streams[0]->codec;
>  
> @@ -350,8 +350,8 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
>              return AVERROR(EIO);
>          }
>          for(i=0; i<3; i++){
> -            if (avio_open2(&f[i], filename, AVIO_FLAG_READ,
> -                           &s1->interrupt_callback, NULL) < 0) {
> +            if ((ret[i] = avio_open2(&f[i], filename, AVIO_FLAG_READ,
> +                                     &s1->interrupt_callback, NULL)) < 0) {
>                  if(i==1)
>                      break;
>                  av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename);
> @@ -370,6 +370,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
>          f[0] = s1->pb;
>          if (url_feof(f[0]))
>              return AVERROR(EIO);
> +        ret[0] = 0;
>          size[0]= 4096;
>      }
>  
> @@ -379,7 +380,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
>  
>      pkt->size= 0;
>      for(i=0; i<3; i++){
> -        if(size[i]){
> +        if(ret[i] >= 0){

does it work if f[i] is checked here ? (and set to NULL at the top)
that would be quite a but simpler

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120907/75cf7b0a/attachment.asc>


More information about the ffmpeg-devel mailing list