-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fseek does not work with php://input when data is not pre-read #9441
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
Comments
Which SAPI are you using? cli? |
@cmb69 I get the same results with Apache and mod_php (Apache 2.4.54) and PHP CLI server. |
I cannot reproduce this (neither with Apache mod_php nor with the builtin server), assuming the request body is not empty; maybe Windows is not affected. |
Oh yeah I'm on debian. I don't have a Windows to test stuff. Also what made me fall into this was the fact that Here is a complete curl trace using the first code example:
|
Also before anyone asks, this is not related to curl using
|
Ah, you've made a PUT request; I've tried with a POST. Not sure if there's a difference, though. |
Same issue with POST, yeah, it's probably coming from the stream handling. I read the code, but I'm not sure where the issue might be. I can see that there is already code to read the stream to the end to try to emulate seeking into a stream, but that might not be related.
|
I can reproduce this on Fedora and PHP 8.1. |
I did a bit of debugging and it's basically that input stream body is a temp stream which has got inner memory stream. The problem is that memory stream currently fails when trying to seek past end which is the case here - if you add more data, then it is ok (e.g. |
Ah! Good find! But… Not really :) Actually what you are referring to works with a longer string and POST request, but il fails with
OK that works as you said. But now with PUT:
As you see, same script, same body data, just a different HTTP request method and it fails. I tested with other methods, eg. DELETE, SEARCH, etc. and it only works with POST, but not with the other methods. I found this bug because I wanted to know the length of |
I changed the title to reflect that it's not a issue with POST but when using other methods. |
The difference is that POST is handled specially by SAPI where Technically it's still a bug even for POST because reading past end should not fail. Obviously it's worse for other methods where the request body is not pre read so you cannot seek even on the supplied data. In any case the core issue is that memory stream fails to seek past end so nothing really changes from my last comment. :) |
Ah! yes I understand, because POST is pre-read, you can seek, but other requests are not read, so you can't seek unless you read them first. That makes sense. So yes it's actually two issues if I understand correctly:
Thanks for your help, I hope we can fix that :) |
Fix in #12058 |
Awesome, thank you @bukka :) |
Description
Resulted in this output:
But I expected this output instead:
If you actually read through to the end of the stream, it becomes seekable:
Results in what is expected:
PHP Version
PHP/8.1.9
Operating System
Debian stable
The text was updated successfully, but these errors were encountered: