[FFmpeg-devel] url_exists function in avio.c opens instead of checking existence

Stefano Sabatini stefano.sabatini-lala
Tue Jan 19 22:35:47 CET 2010

On date Tuesday 2010-01-19 22:05:54 +0100, Maker aka Michele encoded:
> hello. This is my first post, so sorry for my bad English and for whatever
> wrong i will do.

You're welcome.

> I started playing with ffmpeg code in order to try to fix this bug:
> http://thread.gmane.org/gmane.comp.video.ffmpeg.user/24644/focus=24707
> In few words, in avio.c uses url_open to check if an url exists
> (libavformat/avio.c : 199). This is semantically wrong becouse it tries to
> _open_ that file (in read-only) instead of checking his real existence. This
> maybe create bugs if the target file is fifo (it loops), has 000 permissions
> (fails), etc.
> This can happen with whatever protocol.

The bug mentioned which was discussed some time in ffmpeg-user occurs
when we have a process reading in RDONLY mode on a fifo, when ffmpeg
checks for the existence of the file with url_exist() it tries to open
the file in RDONLY mode and hangs since the access in that mode is

Using -y prevents the error, since ffmpeg in that case doesn't check
for the existence of the file but just opens it in WRONLY mode.

> so, I would like to receive some advice before starting:
> my original idea was to extend the original URLProtocol structure (
> doc here<http://cekirdek.pardus.org.tr/%7Eismail/ffmpeg-docs/structURLProtocol.html#eec7eb72a222542a27d237b8cf2671b4>)
> with something like "  int(* url_exists )(URLContext *h, const char
> *filename)  " and create some functions to check if filename exists using
> stats. It's a clear solution, but I would make URLProtocol a little bigger.
>  Then I would make a parse_url function (this actually is done by url_open
> [111:135 lines], but it's not its job) and edit url_exists in order to use
> proto->url_exists.
> Is this solution ok for you, or there's something better I could do?

What about a url_check(file, flag) function, which checks if it is
possible to open a file/url with a certain mode?

Then we could deprecate url_exist() and use that instead.

FFmpeg = Fucking Freak Mythic Portable Ecumenical Game

More information about the ffmpeg-devel mailing list