nette/http

TypError unpack() expects parameter 2 to be string, bool given in Http/Helpers

josefsabl opened this issue · 6 comments

Version: dev-master#db73233

Bug Description

When I run the app on the PHP built-in server I get the unpack() expects parameter 2 to be string, bool given. The reason is that:

  • $_SERVER['REMOTE_ADDR'] === string(5) "[::1]"
  • which gets passed to inet_pton
  • which returns false
  • which is passed to unpack
  • which results in TypeError

See attached tracy.
TypeError_ unpack() expects parameter 2 to be string, bool given.zip

Is this a Nette bug? Is it PHP Server bug? Am I doing something wrong? I don't think I changed anything in the php server settings.

Steps To Reproduce

none

Expected Behavior

no crash, obviously

dg commented

PHP is probably not compiled with IPv6 support http://php.net/manual/en/function.inet-pton.php

dg commented

No, it is caused by square brackets.

I tried run php -S [::1]:8000 and $_SERVER['REMOTE_ADDR'] contains ::1. Which version do you use?

Hey, thanks for reacting so swiftly!

I am using version 7.3.1 for windows.

I am running it through PhpStorm run configuration, that generates command like this:

F:\php\7.3.1\php.exe -S localhost:88 -t F:\Projects\my_project\www --php-ini php.ini F:\Projects\my_project\local\serverRouter.php

When I run it manually similar to your example

F:\php\7.3.1\php.exe -S [::1]:88 -t F:\Projects\my_project\www --php-ini php.ini F:\Projects\my_project\local\serverRouter.php

Problem persists and $_SERVER['REMOTE_ADDR'] contains [::1].

Running it like this doesn't obviously work (generates invalid ip address error)

F:\php\7.3.1\php.exe -S ::1:88 -t F:\Projects\my_project\www --php-ini php.ini F:\Projects\my_project\local\serverRouter.php

Doing:

F:\php\7.3.1\php.exe -S 127.0.0.1:88 -t F:\Projects\my_project\www --php-ini php.ini F:\Projects\my_project\local\serverRouter.php

... however does fix this.

It is obviously some problem with the php itself? I guess that [::1] is invalid ip spec and nothing is wrong with Nette.

Thank you for the direction! I can at last remove the

        if ($_SERVER['REMOTE_ADDR'] === '[::1]') {
            $_SERVER['REMOTE_ADDR'] = '::1';
        };

workaround :-)

PS: The strange thing is that this is the "Worked yesterday" kind of bug :-/

dg commented

It seems like bug in PHP 7.3, previous PHP are correct. Can you report it?

I've already reported it in the PHP for Windows chat channel. Not sure if anyone read it. I will try to report to PHP devs as well.