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

StreamWrapper::stream_stat() should not always return an array #593

Open
chapa opened this issue Jan 19, 2024 · 0 comments · May be fixed by #594
Open

StreamWrapper::stream_stat() should not always return an array #593

chapa opened this issue Jan 19, 2024 · 0 comments · May be fixed by #594

Comments

@chapa
Copy link

chapa commented Jan 19, 2024

PHP version: >= 8.1

Description

StreamWrapper::stream_stat() is returning an array no matter what, this can cause problems when the inner stream has a size of null, because it's then transformed to 0. The information "I don't know the size of this stream" is transformed to "this stream is empty".

Also, I'm wondering, why url_stat() (implemented in #156) does return a mode and a size of 0 unconditionally.

How to reproduce

$r = fopen('https://google.com', 'r');
assert(fstat($r) === false);

$stream = Utils::streamFor($r);
assert($stream->getSize() === null);

$r2 = StreamWrapper::getResource($stream);
assert(fstat($r2) === false); // This fails

$stream2 = Utils::streamFor($r2);
assert($stream2->getSize() === null); // This fails too (0 is returned)

Possible Solution

#594

Additional context

I'm trying to send a request with Guzzle, that request has a null-sized stream body wrapped in StreamWrapper as explained above (for some reasons that I cannot bypass), and Guzzle itself seems to rely on the fact that a 0-sized body should not be sent in a request : https://github.com/guzzle/guzzle/blob/2779e868a00289e1b1fd854af030c43a06f4bcb4/src/Handler/CurlFactory.php#L251.

As a result, the request is sent without it's body.

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

Successfully merging a pull request may close this issue.

1 participant