Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
forgie1 opened this issue Jun 2, 2021 · 1 comment
Closed

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

forgie1 opened this issue Jun 2, 2021 · 1 comment

Comments

@forgie1
Copy link

forgie1 commented Jun 2, 2021

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 ''

forgie1 added a commit to forgie1/safe-stream that referenced this issue Jun 2, 2021
dg added a commit that referenced this issue Jun 2, 2021
@dg
Copy link
Member

dg commented Jun 2, 2021

Thanks, fixed

@dg dg closed this as completed Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants