-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
BinaryFileResponse content corruption under nginx on Azure app service (Linux) #42685
Comments
Can you try the workaround suggested here: #42681 (comment) |
Seems this is a Symfony issue. Please don't upgrade to Symfony v6.1 for now and wait until they release a patch release. |
I am having a similar issue, some details here: |
It is a different manifestation of the same issue. I raised a ticket with Symfony and Azure. They are blaming each other and neither side wants to do the fix. |
Yeah, just found the same azure link. Thanks for the update. It seems the |
Description:
A fairly simple controller which picks form input, chooses image from the disk and then returns it to webbrowser. Eg
The code works absolutely perfectly on local development instance of Laravel (Windows 10), but corrupts data when deployed on Azure PHP App Service on Linux.
I could confirm from debug that the file exists, could be read and contains correct data.
However, when the data arrives to web browser, it is corrupted in a particular way:
Steps To Reproduce:
Run the same code under Windows 10 and under Azure App Service on Linux for PHP 8.0. Below are attached two images - the image stored locally and the image as delivered.
Fix
After lots of headscratching, I found a work around in Symfony code, HOWEVER the problem is not happening in "vanilla" PHP app using Symfony, so I suspect there is a problem with the way Laravel and Symfony interact.
The problem code is this one
namespace Symfony\Component\HttpFoundation;
......
class BinaryFileResponse extends Response
.....
public function sendContent(): static
{
......
stream_copy_to_stream($file, $out, $this->maxlen, $this->offset);
......
}
to fix, I implemented the following - eg PHP native function stream_copy_to_stream is replaced with a custom function, which does (as far as I could tell) the same thing (I have Ranges disabled globally, hence always serve the entire file).
_function pipe_streams($in, $out)
{
$size = 0;
while (!feof($in)) $size += fwrite($out,fread($in,8192));
return $size;
}
{
......
$this->pipe_streams($file, $out);
......
}_
The text was updated successfully, but these errors were encountered: