Opened 12 years ago

Closed 12 years ago

#1904 closed defect (fixed)

image2: cannot open files not readable by owner

Reported by: robert Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: image2
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

Summary of the bug:

file_check() in libavformat/file.c makes loading of image2 sequences fail (not tried with other types of files but I guess it afects all users of this function). The problem is that it checks if the owner has read permissions, but a file can be readable even when the owner has no read permissions if "others" have read permission. This tipically happens on Android systems, for example in the removable sdcard mounted as /mnt/sdcard.

How to reproduce:

Call avformat_open_input() with an image filename in a directory that is not readable by the owner. For example, in a directory with the following permissions: ----r-xr-x

Proposed fix:

divVerent in #ffmpeg@irc.freenode.net proposed this fix:

static int file_check(URLContext *h, int mask)
{
    int ret = 0;
    if(mask&AVIO_FLAG_READ)
        if(access(h->filename, R_OK) >= 0)
            ret |= AVIO_FLAG_READ;
    if(mask&AVIO_FLAG_WRITE)
        if(access(h->filename, W_OK) >= 0)
            ret |= AVIO_FLAG_WRITE;
    return ret;
}

i.e use access() instead of stat(). But he says access() has issues on Windows...

Attachments (1)

patchor.diff (528 bytes ) - added by Carl Eugen Hoyos 12 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Carl Eugen Hoyos, 12 years ago

Priority: criticalnormal

comment:2 by Elon Musk, 12 years ago

Status: newopen

Please send patches to ffmpeg-devel mailing list.

comment:3 by Carl Eugen Hoyos, 12 years ago

Did you test above patch?
Isn't open() refusing to open files if the user does not have the relevant permission himself?

by Carl Eugen Hoyos, 12 years ago

Attachment: patchor.diff added

comment:4 by Carl Eugen Hoyos, 12 years ago

Attached is an alternative patch (that does not work here).

comment:5 by Carl Eugen Hoyos, 12 years ago

Analyzed by developer: set
Keywords: image2 added
Reproduced by developer: set

The patch works fine for this use-case:
$ ls -l tests/lena.pnm
--w----r-- 1 root root 196668 Oct 21 19:06 tests/lena.pnm

in reply to:  3 comment:6 by robert, 12 years ago

Replying to cehoyos:

Did you test above patch?
Isn't open() refusing to open files if the user does not have the relevant permission himself?

Hi cehoyos, I know it's odd but on Android you find those permissions, maybe because every app runs on its own sandbox with its own user, so it wouldn't make sense to make the files owned by a single user. I don't know, it's just an idea...

Regarding your question about open()... it won't fail if "others" have read permission even when the "owner" has no read permissions. If you think your patch is better it's ok, I'm mostly a java programmer and I don't know much about the C apis.

This stackoverflow.com question is related to this issue and the solution is similar to yours: http://stackoverflow.com/questions/7867853/android-ffmpeg-halfninja-av-open-input-file-returns-2-no-such-file-or-director

Thank your for your fast response.

Last edited 12 years ago by robert (previous) (diff)

comment:7 by Michael Niedermayer, 12 years ago

Resolution: fixed
Status: openclosed
Note: See TracTickets for help on using tickets.