dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.89k stars 236 forks source link

Function `htmlspecialchars` on line 124 in `helpers.php` (Laravel) interpreted as function with different name #925

Closed ben221199 closed 3 months ago

ben221199 commented 3 months ago

What happened?

I run a Docker container with Laravel and FrankenPHP in its Docker image. Everything works fine and the issue isn't there anymore when I kill the running container and spawn a new (identical) one.

After some time, something happens to the container, but I don't know exactly what. In Blade, {{ $var }} is converted to <?php e($var); ?> when cached. This function e is defined in the helpers.php file. On line 124 in this function, the htmlspecialchars is called with 4 parameters, according to the source code.

However, this is not what happens in my container at some point. In the beginning, it just calls htmlspecialchars, but when the container is older, it somehow calls rmdir or session_set_cookie_params, or another random function. The name htmlspecialchars isn't even seen in the logs. It looks like calling htmlspecialchars() is totally replaced with rmdir(), even when the source code stays the same.

Could this be a memory leak?

NOTE: The container runs in production.

Build Type

Docker (Alpine)

Worker Mode

Yes

Operating System

GNU/Linux

CPU Architecture

x86_64

PHP configuration

N/A

Relevant log output

INFO  [previous exception] [object] (ArgumentCountError(code: 0): rmdir() expects at most 2 arguments, 4 given at vendor/laravel/framework/src/Illuminate/Support/helpers.php:124).  
   INFO  [stacktrace].  
   INFO  #0 vendor/laravel/framework/src/Illuminate/Support/helpers.php(124): rmdir(1, 11, 'UTF-8', true).  
   INFO  #1 storage/framework/views/f8ff7283bc11ffa7e3469449fa58f568.php(6): e(1).  
   INFO  #2 vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(123): require('storage/fr...').  
   INFO  #3 vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(124): Illuminate\\Filesystem\\Filesystem::Illuminate\\Filesystem\\{closure}().  
   INFO  #4 vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\\Filesystem\\Filesystem->getRequire('storage/fr...', Array).  
   INFO  #5 vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(72): Illuminate\\View\\Engines\\PhpEngine->evaluatePath('storage/fr...', Array).  
   INFO  #6 vendor/laravel/framework/src/Illuminate/View/View.php(207): Illuminate\\View\\Engines\\CompilerEngine->get('resources/...', Array).  
   INFO  #7 vendor/laravel/framework/src/Illuminate/View/View.php(190): Illuminate\\View\\View->getContents().  
   INFO  #8 vendor/laravel/framework/src/Illuminate/View/View.php(159): Illuminate\\View\\View->renderContents().  
   INFO  #9 vendor/laravel/framework/src/Illuminate/View/Factory.php(189): Illuminate\\View\\View->render().
withinboredom commented 3 months ago

Seems like a regression of an opcache bug. You didn't provide phpinfo output, so we have no idea what versions you are running. Can you please provide that output?

ben221199 commented 3 months ago

image

withinboredom commented 3 months ago

The screenshot isn't immediately useful, but 8.2.19 came out quite awhile ago. What version of frankenphp are you running? Have you tried upgrading to the latest versions?

ben221199 commented 3 months ago

I used FROM dunglas/frankenphp:latest-php8.2-alpine. I will look which version that is currently in my image.

ben221199 commented 3 months ago
ben221199 commented 3 months ago

I want to update my site, but also want to keep the current version to see if this happens again. Therefore, I change the Docker image to 1.1.5-php8.2-alpine. (I could have choosen 1.1.5-php8.2.19-alpine too, because it is likely the same image.)

withinboredom commented 3 months ago

This is most likely a memory corruption issue and not a Frankenphp issue. Without more information and some way to reproduce this, I'm going to go ahead and close this. We're still here though.

ben221199 commented 3 months ago

Fair enough. I will look if I can find more information about it.

ben221199 commented 3 months ago

Okay, it happened again multiple times and it was a different function every time. I'm wondering how I can setup something for reproduction without my repository.

@withinboredom Do you have some commands I can run that give you some information about what is happening? Then we can likely know if this an PHP or an FrankenPHP bug.

withinboredom commented 3 months ago

This seems like a memory corruption issue, either by php, or an extension. It plagued certain versions of opcache + 8.1/8.2 zts builds. I haven't seen it with 8.3.

This is unlikely to be a frankenphp bug. I recommend updating frankenphp and potentially updating to php 8.3.

ben221199 commented 2 months ago

I changed dunglas/frankenphp:1.1.5-php8.2-alpine to dunglas/frankenphp:1.1.5-php8.3-alpine. I will see what that will do.