Skip to content

PHP8 -- not working: fopen('safe://' . some_file_path, 'a'); #10

@forgie1

Description

@forgie1

Version: 2.4.1
Ubuntu 20.04.2 LTS
PHP 8.0.5

Bug Description

fopen('safe://' . 'some_file_path', 'a');
results in:
stream_copy_to_stream(): Read of 8192 bytes failed with errno=9 Bad file descriptor

Expected Behavior

fopen('safe://' . some_file_path, 'a');
opens the file
file didn't exist on the given path, so it should be created

Possible Solution

SafeStream.php:114
if (stream_copy_to_stream($this->handle, $this->tempHandle) !== $stat['size']) {

tries to read from file $this->handle opend with readonly mode 'x'
this looks like proper behavior of PHP - not a bug in PHP:
https://bugs.php.net/bug.php?id=78482

if the file would be open with flag 'x+', everything works just fine:
SafeStream.php:89
if ($this->checkAndLock($this->handle = @fopen($path, 'x' . $flag, $use_path), LOCK_EX)) {
if $flag would be '+' -- works fine, but $flag is empty string ''

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions