Opened 4 years ago

Closed 4 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 cehoyos 4 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by cehoyos

  • Priority changed from critical to normal

comment:2 Changed 4 years ago by richardpl

  • Status changed from new to open

Please send patches to ffmpeg-devel mailing list.

comment:3 follow-up: Changed 4 years 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 4 years ago by cehoyos

comment:4 Changed 4 years ago by cehoyos

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

comment:5 Changed 4 years 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 4 years 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.

Thank your for your fast response.

Version 0, edited 4 years ago by robert (next)

comment:7 Changed 4 years ago by michael

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