-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Verify size of installed packages array #11304
Conversation
`self::getInstalled()` can return empty array. We should validate key existence to prevent exception like: ``` Exception: Notice: Undefined index: versions in /.../vendor/composer/composer/src/Composer/InstalledVersions.php on line 54 in /.../vendor/magento/framework/App/ErrorHandler.php:61 ```
`self::getInstalled()` can return empty array. We should validate key existence to prevent exception like: ``` Exception: Notice: Undefined index: versions in /.../vendor/composer/composer/src/Composer/InstalledVersions.php on line 54 in /.../vendor/magento/framework/App/ErrorHandler.php:61 ```
This does not make sense. A and this |
Yes, you are right. My first fix was:
but I had an error in PHPStan verification:
I don't know how to fix PHPStan rules :( |
Those |
Well I am still not sure what this fixes. It seems what @stof said above is still in the PR, I don't see a problem returning an empty array here. Please explain the intent or let's close this. |
Empty array will throw an exception (Undefined index: versions) in 'array_keys($installed['versions'])' in case of
|
No? Empty array will never enter the foreach? |
Yes, you are right. I did not explain the problem correctly. It was too long time ago :) In this place
If result of |
Sorry I just still don't get it, here is the code from getInstalledPackages:
Now if we replace getInstalled by an empty array we get:
So foreach of an empty array does nothing, so we can remove the foreach:
Then we get an empty $packages, so the if here does not match for sure so we remove it:
And now we're left with this which evaluates fine: https://3v4l.org/ss0f9 So I don't understand where you get an exception. |
Probably it's related with #9937 when uses if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = require __DIR__ . '/installed.php';
} else {
self::$installed = array();
}
}
$installed[] = self::$installed; If the 1st condition is true and the 2nd condition = false self::$installed = array();
$installed[] = self::$installed; Return result is $installed = [[]] Now if we replace getInstalled we get: foreach ([[]] as $installed) {
$packages[] = array_keys($installed['versions']);
} |
Thanks, @vtsykun , exactly:
|
Oh ok ok now I see it thanks :D I'll fix this |
self::getInstalled()
can return -empty array- array with empty array. We should validate key existence to prevent exception like: