[FFmpeg-devel] fix ftp hang up because not return AVRRROR_EOF

Submitted by Jan Ekström on June 13, 2018, 6:18 p.m.

Details

Message ID CAEu79Sad-KOcqb_kfoz_egS-oXQTo__HXO_J8cq_NtBzX8pWzA@mail.gmail.com
State New
Headers show

Commit Message

Jan Ekström June 13, 2018, 6:18 p.m.
On Wed, Jun 13, 2018 at 1:27 PM, Gj X <xiong2634528861@gmail.com> wrote:
> fix:
> diff --git a/libavformat/ftp.c b/libavformat/ftp.c
> index 9aa7a45629..3474a0adbc 100644
> --- a/libavformat/ftp.c
> +++ b/libavformat/ftp.c
> @@ -777,7 +777,11 @@ static int ftp_read(URLContext *h, unsigned char *buf,
> int size)
>  {
>      FTPContext *s = h->priv_data;
>      int read, err, retry_done = 0;
> -
> +    if(s->position >= s->filesize)
> +    {
> +        ff_dlog(h,"ftp protocol reach file end\n");
> +        return AVERROR_EOF;
> +    }
>      ff_dlog(h, "ftp protocol read %d bytes\n", size);
>    retry:
>      if (s->state == DISCONNECTED) {
>

Hi,

Thanks for your contribution. I just looked at that function and it
seems like `ftp_read` needs some improvement.

But staying on the 0 != EOF fixup topic, probably something like this
should prod it to work:

     }
@@ -823,7 +823,7 @@ static int ftp_read(URLContext *h, unsigned char
*buf, int size)
                 goto retry;
             }
         }
-        return read;
+        return read ? read : AVERROR_EOF;
     }

     av_log(h, AV_LOG_DEBUG, "FTP read failed\n");

Patch hide | download patch | download mbox

diff --git a/libavformat/ftp.c b/libavformat/ftp.c
index 9aa7a45629..f07e9fcdd9 100644
--- a/libavformat/ftp.c
+++ b/libavformat/ftp.c
@@ -783,13 +783,13 @@  static int ftp_read(URLContext *h, unsigned char
*buf, int size)
     if (s->state == DISCONNECTED) {
         /* optimization */
         if (s->position >= s->filesize)
-            return 0;
+            return AVERROR_EOF;
         if ((err = ftp_connect_data_connection(h)) < 0)
             return err;
     }
     if (s->state == READY) {
         if (s->position >= s->filesize)
-            return 0;
+            return AVERROR_EOF;
         if ((err = ftp_retrieve(s)) < 0)
             return err;