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

determineCanonicalRootUrl may cause crash in PHP 8.1 #12

Open
rgvy opened this issue Dec 13, 2021 · 5 comments
Open

determineCanonicalRootUrl may cause crash in PHP 8.1 #12

rgvy opened this issue Dec 13, 2021 · 5 comments
Labels

Comments

@rgvy
Copy link

rgvy commented Dec 13, 2021

For some reason determineCanonicalRootUrl(false) returned a null. In the constructor of App, calling urldecode(null) causes a crash in php 8.1. While I'm working to fix my problem with determineCanonicalRootUrl, a crash can be avoided by coalescing urldecode(null ?? '').

@rgvy
Copy link
Author

rgvy commented Dec 13, 2021

Specifically the problem appears to be with parse_url using the PHP_URL_PATH option. There is no terminal '/' character from the determineCanonicalRootUrl result. It looks like it gets stripped in that method, then parse_url returns null, which crashes urldecode in php 8.1. I'm using https://localhost:8888/ as my APP_PUBLIC_URL.

@rgvy rgvy changed the title determineCanonicalRootUrl may cause crash in Swift 8.1 determineCanonicalRootUrl may cause crash in PHP 8.1 Dec 14, 2021
@ocram ocram added the question label Dec 15, 2021
@ocram
Copy link
Contributor

ocram commented Dec 15, 2021

Thank you!

I don’t think PHP 8.x handles paths and hosts different from PHP 7.x with parse_url. PHP 8.0 only changed the behavior for missing/empty query strings and fragments.

You’re probably talking about App#__construct, right?

Which of the following three lines is failing exactly, and where is the cause of the error in your opinion?

!empty($this->canonicalRootUrl[0]) ? \parse_url($this->canonicalRootUrl[0], \PHP_URL_HOST) : null,

// or

!empty($this->canonicalRootUrl[1]) ? \parse_url($this->canonicalRootUrl[1], \PHP_URL_HOST) : null

// or

$canonicalRootPath = \urldecode(\parse_url($this->canonicalRootUrl[0], \PHP_URL_PATH));

(By the way, any chance you could let this run on port 80 instead of 888?)

@rgvy
Copy link
Author

rgvy commented Dec 15, 2021

The easiest fix for php 8.1 would be to just coalesce with an empty string like this:

$canonicalRootPath = \urldecode(\parse_url($this->canonicalRootUrl[0], \PHP_URL_PATH) ?? '');

Apologies, but I haven't traced the issue through the determineCanonicalRootUrl method. Apparently it isn't causing me any problems.

@ocram
Copy link
Contributor

ocram commented Dec 15, 2021

Thanks!

I would include the null check, sure, but it would be good to know where exactly it fails and why, and actually understand the behavior and what we want.

As I said, \parse_url(..., \PHP_URL_PATH) should not behave any different on PHP 8.x, compared to 7.x. So any problem that occurs has probably been present on previous PHP versions as well.

@rgvy
Copy link
Author

rgvy commented Dec 15, 2021

Maybe this has always been a bug that never caused any problems. It looks like determineCanonicalRootUrl always strips the final '/' character, and \parse_url(..., \PHP_URL_PATH) always returns null if there is no final '/' character. In the App constructor, the result is only used to construct a Router (with the local var canonicalRootPath). Because the App's Router is designed to be a root-level router, perhaps it never caused any problems to use a null path in its construction. In the Router, the value is saved to the rootPath which is only used in the createRouteRegex method. Without a root path, the regex would match more (not less) which would hide this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants