Ticket #1904 (closed defect: fixed)

Opened 6 months ago

Last modified 6 months ago

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@… 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

patchor.diff Download (528 bytes) - added by cehoyos 6 months ago.

Change History

comment:1 Changed 6 months ago by cehoyos

  • Priority changed from critical to normal

comment:2 Changed 6 months ago by richardpl

  • Status changed from new to open

Please send patches to ffmpeg-devel mailing list.

comment:3 follow-up: ↓ 6 Changed 6 months ago by cehoyos

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

Changed 6 months ago by cehoyos

comment:4 Changed 6 months ago by cehoyos

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

comment:5 Changed 6 months ago by cehoyos

  • 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

comment:6 in reply to: ↑ 3 Changed 6 months ago by robert

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 6 months ago by robert (previous) (diff)

comment:7 Changed 6 months ago by michael

  • Status changed from open to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.